Asm code
Code:
.386
public MyFunction
MyFunction PROC arg1:DWORD, arg2:DWORD
MyFunction ENDP
C module
Code:
//Declare prototype for MyFunction
//Specify C to prevent name mangling
//Specify extern because the body of this function lies outside of
//the current module
extern "C" MyFunction(DWORD arg1,DWORD arg2);
int main(void)
{
MyFunction(10,20);
return(0);
}
In C/C++ all integral return values are returned in EAX and all floating point return values are returned in ST(0).
Also you should know which calling mode is being used as this determines in what order the parameters are pushed onto the stack.
But for all 32-bit programs:
EBP - last value of EBP
EBP+4 - address of caller - return address
EBP+8 - first parameter starts here
When mixing pure assembly code and C/C++ you will always want to use the following if you are doing anything with parameters:
Note this is TASM syntax, not MASM:
Code:
MyFunction PROC
ARG value1:DWORD,value2:DWORD
;always start with this
push ebp
mov ebp,esp
;always end with this
pop ebp
MyFunction ENDP
Failing to do this will crash the compiler and perhaps even Windows - yes, even XP. This is a requirement in TASM when using the ARG directive and I'm sure it probably is in MASM as well.
NASM also must conform to this standard in order to function correctly when being mixed with C/C++ code.