Page 1 of 1

OOP asm

Posted: Fri Aug 24, 2007 5:15 am
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?

Posted: Fri Aug 24, 2007 8:54 am
by Solar
I'd suggest you look at the C++ ABI.

Posted: Fri Aug 24, 2007 9:54 am
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. ;)

Posted: Fri Aug 24, 2007 11:22 am
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

Posted: Sat Aug 25, 2007 11:01 am
by SpooK
-----> ObjAsm32 <-----

Posted: Sat Aug 25, 2007 4:25 pm
by binutils
maybe it would be good to extract gtk libraries' framework using (idc <-> gcc -S).

I think.....

Posted: Mon Aug 27, 2007 9:09 am
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...

Posted: Mon Aug 27, 2007 11:02 am
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?

Posted: Tue Aug 28, 2007 10:30 am
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.