does anybody knows how code objects directly in ASM ?

For example:

class myClass{
var myVariable;
function setVariable(){
this.myVariable = "Hello ASM Coder";
}
}

with the call:

// init class
myNiceClass = new myClass();

// now set variable
myNiceClass.setVariable();

//and print
print (myNiceClass.myVariable);


How would this look, if I would code this directly in ASM ?

Thx for any comment
:)


Zero
Posted on 2002-06-21 06:51:06 by Zero
This question gets asked over and over.... do a search on the board, you'll find some good results.
Posted on 2002-06-21 09:06:13 by Asm_Freak
Asm_Freak, in my opinion, it doesnt get asked enought ;) . But you do have a point, one should try the search function first if they remember to do so...

Zero, Since a rock nearly missed my house by a meager 75,000 km, last week. Im in a more caring mood these days and decided to to a litteral 1:1 translation of your example code with our (Thomas and I) OOP Model:

The Class Definition File
IFNDEF _myClass_

_myClass_ equ 1

[b]; --============================================
; #CLASS: myClass
; #VERSION: 1.0
; --============================================
; Built by NaN's Object Class Creator
; _ Sept 19, 2001
;
; By NaN ( [email]jaymeson@hotmail.com[/email] )
; [url]http://nan32asm.cjb.net[/url]
;
; --============================================
; #AUTHOR: NaN
; #DATE: Sept. 25, 2001
;
; #DESCRIPTION:
;
; Test "Hello World" class for example.
;
; --============================================
; CLASS METHOD PROTOS
; --============================================
[/b] myClass_Init PROTO :DWORD

[b]; --============================================
; FUNCTION POINTER PROTOS
; --============================================
[/b] myCl_destructorPto TYPEDEF PROTO :DWORD
myCl_PrintPto TYPEDEF PROTO :DWORD
myCl_SetVariablePto TYPEDEF PROTO :DWORD

[b]; --============================================
; CLASS STRUCTURE
; --============================================
[/b] CLASS myClass, myCl
CMETHOD destructor ; MUST BE THE FIRST, OR OBJECTS.INC WILL FAIL
CMETHOD Print ; Used to create a Message Box, and Print the Variable Data
CMETHOD SetVariable ; Used to fill the internal buffer with a text string
PrivateBuffer dd 32 dup(?) ; 128 byte buffer
myClass ENDS

.data

BEGIN_INIT
dd offset myCl_destructor_Funct
dd offset myCl_Print_Funct
dd offset myCl_SetVariable_Funct
dd 32 dup( 0 ) ; 32 NULL's for initial buffer.
END_INIT

.code
[b]; --============================================
; #METHOD: CONSTRUCTOR (NONE)
;
; #DESCRIPTION: Empty Constructor, that does nothing specific..
;
; --============================================
[/b]myClass_Init PROC uses edi esi lpTHIS:DWORD
SET_CLASS myClass
SetObject edi, myClass


ReleaseObject edi
ret
myClass_Init ENDP

[b]; --============================================
; #METHOD: destructor (NONE)
;
; #DESCRIPTION: Empty Destructor, that does nothing specific..
;
; --============================================
[/b]myCl_destructor_Funct PROC uses edi lpTHIS:DWORD
SetObject edi, myClass


ReleaseObject edi
ret
myCl_destructor_Funct ENDP

[b]; --============================================
; #METHOD: Print()
;
; #DESCRIPTION: Creates a Message Box with the String Data, IF and only IF the string
; string is set using the SetVariable Method..
;
; --============================================
[/b]myCl_Print_Funct PROC uses edi lpTHIS:DWORD
SetObject edi, myClass

mov al, BYTE PTR [edi].PrivateBuffer ; Get first buffer byte
cmp al, 0 ; See if its NULL
je @F ; Yes, then dont print, and exit
invoke MessageBox, NULL, addr [edi].PrivateBuffer, ; Print Out the Message
NULL, MB_OK ;
@@: ; Exit
ReleaseObject edi
ret
myCl_Print_Funct ENDP

[b]; --============================================
; #METHOD: SetVariable()
;
; #DESCRIPTION: Fills a private class buffer with string data..
;
; --============================================
[/b]myCl_SetVariable_Funct PROC uses edi lpTHIS:DWORD
SetObject edi, myClass
.data
SetDataString db "Hello ASM Coder, this is the NaN/Thomas OOP model!",0
.code

invoke StrLen, addr SetDataString
mov edx, eax
invoke MemCopy, addr SetDataString, addr [edi].PrivateBuffer, edx

ReleaseObject edi
ret
myCl_SetVariable_Funct ENDP

ENDIF


The Main File
.386

.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib

include \masm32\include\Objects.inc ; Our Object Include Macro Set
include myClass.asm ; The Class Definition File

.data?
[b] myNiceClass dd ? ; Class Instance Handle
[/b]
.code
start:

[b] mov myNiceClass, $NEW( myClass ) ; init class: myNiceClass = new myClass()

METHOD myNiceClass, myClass, SetVariable ; now set variable: myNiceClass.setVariable();

METHOD myNiceClass, myClass, Print ; and print: print (myNiceClass.myVariable);

DESTROY myNiceClass ; Must Clean up when finished.
[/b]
invoke ExitProcess, NULL
end start
end


As well, below is the compiled source.
Look it up in the \Masm32\OOP dir as well for more examples,
and please feel free to ask questions, but take them to the COM
section (since OOP more or less fits in this catagory ;) )

Enjoy
:alright:
NaN
Posted on 2002-06-21 10:42:08 by NaN
Asm_Freak:
Yep. You are right. For the search before asking... really forgot to do so ;) Normally I kill the people at my own board, if they don?t do so... Sorry :(

NaN:
Yes. This is EXACTLY what I searched for ! Give me some time to check and understand it ;)

:alright: Congrats for 1111 posts !

Zero:
Posted on 2002-06-21 10:59:02 by Zero