View Full Version: Objects in Assembly

meos32 >>Useful Routines >>Objects in Assembly


Solidus117- 03-13-2006
Objects in Assembly
Hiya! Consider the following code (for DOS .COM files (as an example)): org 100h @@: mov ah,07h ; Get Char int 21h mov [kbuffer],al mov ah,02h ; Print Char mov dl,[kbuffer] int 21h cmp [kbuffer],'!' ; Test je @f jmp @b @@: ; Terminate mov ah,4Ch mov al,[exitcode] int 21h kbuffer db 0 ; Data exitcode db 0 That's 15 lines of code!! OMFG you might say. Anyway, I tossed this idea around in my mind last night, then implemented it: include "MyObjects.inc" org 100h MyObj TestObj ; Declare Object (Really just a struc in disguise) @@: call MyObj.getchar ; Get Char call MyObj.putchar ; Print Char cmp [MyObj.kbuffer],'!' ; Test je @f jmp @b @@: call MyObj.term ; Terminate Now it's 9 lines of code. The following is in the included file "MyObjects.inc": struc TestObj { jmp .endofobject .exitnum db 0 .kbuffer db 0 .getchar: mov ah,07h int 21h mov <.kbuffer>,al ret .putchar: mov ah,02h mov dl,<.kbuffer> int 21h ret .term: mov ah,4Ch mov al,<.exitnum> int 21h .endofobject: } So there we have it, code and data encapsulation into an Object. I haven't seen this before, and I was just doing some C++ last night - Eureka!! Maybe this helps, maybe it doesn't, so tell me what you think. Solidus. Edit: You might notice the jump at the start of the 'Object'. This is so that the object can be declared anywhere. It can be easily rempoved and placed in a data section (well, an executable data section).

Dex- 03-13-2006

Is your idea simular to v2os 0.70 ?. http://v2os.v2.nl/cgi-bin/v2wiki.py?show=Index#1

Don- 03-14-2006

is it the same as using macros in fasm???

Solidus117- 03-14-2006

Yep. Pretty Much. But these can be declared multiple times as separate entitites.

bubach- 03-15-2006

I can't understand why any assembly programmer would like to use **** like oop..? :P

Don- 03-15-2006

interesting reading about OOP http://artlung.com/smorgasborg/Invention_of_Cplusplus.shtml summary: don't use it, it's slower and having a great processor is not excuse to waste it ;) :P

Solidus117- 03-15-2006

@Bubach: Basically I did it for shits and giggles. I've been learning C++ over the holidays, so that is my hobby's birthchild - sorta. For an application, a multithreaded app could use varied instances of the same class (ie an instance of a window class could vary among threads - or sth like that). Solidus.

trolly- 01-22-2007

that's not exactyl a object code; because in (for example) c++; the function are not in the structure ; in the structure it's only pointers to the function.

Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.