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).
@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.