OOP asm

Programming, for all ages and all languages.
Post Reply
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

OOP asm

Post by AndrewAPrice »

I'm reading The Art of Assembly Language chapter 14: Classes and Objects. While this is all and well, it is targeted at HLA. Can anyone show me a (non-high level) assembly example of OOP? How do you deal with accessing members, inheritance, and polymorphism?
My OS is Perception.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

I'd suggest you look at the C++ ABI.
Every good solution is obvious once you've found it.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

You could also try using gcc's -S options to get some assembly.

From when I did it, I found that GCC declares an area of memory and uses that as the class. Then, it creates all member functions as normal functions. So, for example, let's say I do this:

Code: Select all

monkey.i = 12;
monkey.koo();
I get:

Code: Select all

movl	$12, monkey(%rip)
movl	$monkey, %edi
call	koo
The member variables are simply indexes to the allocated class space and the functions are just normal functions that take the address of the class automatically.

From what I can tell a lot(most?) of the OOP is pre calculated by the compiler before compile time.

As for the inheritance, it would appear as though the compiler handles all of the dirty work before compilation. I derived a class d from class c and found the only difference in the instance of class d named monkey was that it's size had increased from 16 to 24. Moreover, the member calls from d acted as though they were written in c. (ie. They acted the same as the call described above.)

When virtual functions were added to the mix, a table in the form of entries of this nature endued:

Code: Select all

_ZTV1d:
	.quad	0
	.quad	_ZTI1d
	.quad	_ZN1d3eatEv
	.weak	_ZTI1d
	.section	.rodata._ZTI1d,"aG",@progbits,_ZTI1d,comdat
	.align 16
	.type	_ZTI1d, @object
	.size	_ZTI1d, 24
(Formally called the Virtual Method Table)

Note: I haven't read the ABI, so I could (probably are) a little (a lot?) off. This is all just a bit of disassembly work. ;)
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

You could take a look at v2_os 0.70 which is a (oop) assembly OS.
http://v2os.v2.nl/cgi-bin/v2wiki.py?show=WhatIsV2OS
SpooK
Member
Member
Posts: 260
Joined: Sun Jun 18, 2006 7:21 pm

Post by SpooK »

-----> ObjAsm32 <-----
User avatar
binutils
Member
Member
Posts: 214
Joined: Thu Apr 05, 2007 6:07 am

Post by binutils »

maybe it would be good to extract gtk libraries' framework using (idc <-> gcc -S).
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

I think.....

Post by DeletedAccount »

I am not such a great asm hacker ... Still it seems thats
David Bell's Assembly Language Book has some material
on the subject......

Other than HLA ....
take a look at 1) Terse
2) C--
etc...
bontanu
Member
Member
Posts: 134
Joined: Thu Aug 18, 2005 11:00 pm
Location: Sol. Earth. Europe. Romania. Bucuresti
Contact:

Post by bontanu »

TASM supported OOP and it's manual contained info about OOP in ASM from year 1995 or before. Objects, multiple Inheritance, polymorphism, virtual methods etc. Never seen it to be used very much.

It is not hacking. Simply the same OOP like in any other programing languages.

The powerful macro system from ASM alows you to also develop your own OOP in ASM if you so like... Some did like this (ObjASM, ULTRANO's ATC)

But when you can develop things so fast and simple in ASM who needs OPP anyway?
Ambition is a lame excuse for the ones not brave enough to be lazy; Solar_OS http://www.oby.ro/os/
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

bontanu wrote:But when you can develop things so fast and simple in ASM who needs OPP anyway?
/me ports his OS to a significantly differing system by replacing the core of the kernel and recompiling the rest.

If I used asm for my drivers, I'd be screwed.
Post Reply