I try to understand the logics behind oop in masm...........
can someone help me with a simple oop example.

i suggest the object integer. (not quiet a usefull object but it's abstract enough)
the methods are setValue
getValue
the propertie of the class integer is value (double word)

I want to make it (for have some experience with oop in masm) but cannot work it out.
everytime i wanna call an new instance the program fails to compile.

my question: can someone give me a working example of (e.g.) this object?
please don't say make it with the oop stuff in masm because this works only to create the object.
Posted on 2003-12-26 08:22:02 by raidu
here you are, raidu :grin:

also, there are 10 more tutorials I wrote, in the 5-star rated topic in this forum.
Posted on 2003-12-26 08:41:50 by Ultrano
oops, forgot the attachment... gotta study some things for Dreamer, must build my tighter schedule..
anyway, have fun :D There'll be new release of DR in 2 weeks I hope
Posted on 2003-12-26 08:43:56 by Ultrano
Afternoon, raidu.

Attached is another example.

I don't like using macros very much as it makes code assembler-specific.:tongue:

The zip includes a "test" proggy which shows how to use the SSInteger object.
i.e.


invoke SSInteger_NewObject
mov theInteger, eax

invoke SSInteger_getValue, theInteger
mov theValue, eax

invoke SSInteger_setValue, theInteger, 135

invoke SSInteger_DeleteObject, theInteger


The object code is built into a static library file. Using a static lib means that you don't have to be concerned with having the correct inc/lib files in their appropriate directories just to use the object. You only have to include the prototype file plus the static lib, and away you go:alright: .

You mentioned that you're trying to understand the logics behind OOP in Masm:
This is the way I do it:
An object has a struct which is filled with whatever data this object can handle. In the case of the SSInteger object: it's just a single dword myvalue.


SSIntegerStruc struct DWORD

myvalue dd ?

SSIntegerStruc ENDS


When creating a new object, what you're really doing is creating this structure in memory.
That's why SSInteger_NewObject uses HeapAlloc to allocate the new memory the size of SSIntegerStruc, and then return the pointer to this new memory location.
SSInteger_DeleteObject frees this memory using HeapFree.

SSInteger_setValue and SSInteger_getValue access parts of the struct. In this object, they just set the data or return its value.

Cheers,
Scronty
Posted on 2003-12-26 16:49:41 by Scronty
i think that the functions heapalloc etc... those functions are that I wasn't aware of. As a dos programmer it isn't quit "logic (call me a Vulcan if you want but for me everything must be LOGIC" to have such a big library allocated somewhere in the os kernel or where ever it will be.
By the way, what's that ACT or ATC version you mention in your program and where can I find the oop tutorial or isn't it finished yet.
either way I start experimenting and put the working examples on this forum for other oop-liking programmers here.
The main part is that points to our newly created object right?

so: I declare the object as a structure in assembly with lets say:

myObject struc
propertie1 dd ?
.
.
propertien db ?
ends

but what to do with the methods?

must i put them in the structure too?
Posted on 2003-12-27 04:17:53 by raidu
"ATC" can be found here:
http://www.asmcommunity.net/board/index.php?topic=15422&pagenumber=2
10 tutorials. When I find enough will and time, I'll continue the tutorials, which'll include practical examples, conversion of C++ code into asm, making host-plug connections, and the most important - finding the border between oop and scalar coding - knowing it is the most important thing for serious coders. Last night I made an online chess game
http://www.asmcommunity.net/board/index.php?topic=16572
at some point I thought it might be put also as an oop tutorial, but in the end it's not good at all.

btw, my friend EvilHomer once said "if ASM didn't evolve, I'd be as well coding in machinecode." So, keeping it all too real isn't good at all.
Posted on 2003-12-27 07:39:44 by Ultrano
i download the tutorials right now and start reading them. By the way, your example of integer are well understood by me, in fact that object is already stored on my server (thanks a lot). I try now to understand the object.inc file (included with masm), but that's another story. I emailed the authors of that file to give a simple example on how to use it in a program. From the moment i have a respons, i will put the samples on this forum for other OOP programmer newbies.
Posted on 2003-12-28 07:43:11 by raidu
too scronty and Ultrano,

thanks for your examples, now that I managed this stuff, i wonder about the next:

how are VIRTUAL methods implemented in assembler. rememeber I use masm32v8
Posted on 2004-01-07 12:24:06 by raidu
"virtual" with my class.inc registers a function with the currently defined class. When "endclass" macro is reached, the virtual table (a dword array of pointers to functions) gets built, and class structure is meanwhile defined. The inherited functions get listed to the deepest level, and then on the way up they get replaced if the inheriting class defines such a function, too. See the code of "virtual macro " :)
I have completed Dreamer1.5, so I have free time now, I'll add some more functions to ATC - not only "virtual" but also uhm, "void" or I don't know what to call it yet. Because there are very peculiar things around "virtual", and I must optimize ATC to max... polymorphism needs the "call dword ptr" always.
I'll continue the oop tutorials soon.
Posted on 2004-01-07 12:50:03 by Ultrano
Hi,Raidu,here are something I finished about one year and a half ago,
Csprite.zip is original OOP assembly,actually it is done in concept of static struc.
Masm32obj2.zip is something I changed in the concept of static struc.
Since these things were done about a year ago, I have forgotten most delicate parts of programming procedure.
So if you have any questions, I will try to take a look again but may not be able to answer correctly.
Posted on 2004-02-15 22:41:46 by yhcheng
masm32obj1.zip
Posted on 2004-02-15 22:48:51 by yhcheng
Masm32obj2.zip
Posted on 2004-02-15 22:49:35 by yhcheng
Sorry!, the above masm32obj1.zip and masm32obj2.zip are both codes for static struc.
The following masm32objd1.zip and masm32objd2.zip should be the correct codes for a dynamic struc.
Posted on 2004-02-16 05:27:41 by yhcheng
masm32objd2.zip
Posted on 2004-02-16 05:29:13 by yhcheng
ok, thanks a lot.
I will try to find everything out, and if i have got any questions i will SURELY ask them too you.
thanks a lot.

Raidu
Posted on 2004-02-16 15:58:36 by raidu
resource for smilies
Posted on 2004-02-17 11:25:35 by yhcheng