first thing first: there is NO standart for naming
functions in CPP ( GCC uses its own standart )
"_Z4Drawii" means a string with length 4 "_Z4"
"Draw" and that this function takes two integer "i"
parameters.
double DoSth ( int , char , unsigned int );
would be named something like "_dZ4DoSthicu" in GCC
you can decode it by yourself, now lets return to
our main subject
-----------------------------------------------------
there are two ways to get rid of CPP naming problem.
first is ( only in GCC ), prototype the function like the
following. The string in asm () will be the name of the
function in the assembly output of the compiler.
so if you write your draw function in NASM
the linker ld will link this to "void draw ( void )"
in GCC
------
void draw ( void ) asm ( "draw" );
in NASM
--------
draw:
...
ret
the second way is: extern "C" a function
in GCC
------
extern "C" void draw ( void );
in NASM
--------
_draw: ; you must put an "underscore"
...
ret
any C ( extern "C" ) function will be put to asm
by putting an underscore at the beginning of the
method name.
REMEMBER:
you CANNOT use ANY CPP functionality if you
extern "C" a function. overloading, using in a class
as a member function is impossible.
but if you use asm() you can put it anywhere.
but remember also, class member functions take
a pointer to "this" as its hidden first parameter.
in GCC
------
class SomeClass {
int ss1;
int ss2;
...
void doSth ( int par1 , int par2 ) asm ( "doSth" );
...
};
in NASM
--------
; doSth ( SomeClass* this , int par1 , int par2 )
doSth:
push ebp
mov ebp , esp
; [ ebp ] = pushed ebp
; [ ebp + 4 ] = return ip
; i hope i dont need to explain why they are
; multiple of 4... because sizeof(int) = 4
mov edi , [ ebp + 8 ] ; edi = this;
mov ecx , [ ebp + 12 ] ; ecx = par1
mov edx , [ ebp + 16 ] ; edx = par2
mov eax , [ edi ] ; get first class member
; property "ss1" to eax
mov ebx , [ edi + 4 ] ; get second class member
; property "ss2" to ebx
...
pop ebp
ret