
Extremely Active Member
     
Group: Admins
Posts: 2301
Member No.: 160
Joined: 22-June 04

|
there are many ways to call procedure with parameters and return, they are described in "calling conventions" (look web for details).
most common under win32 is "stdcall":
| CODE | ... ; -- <- stack push 25 ; 25 call my_proc ; 25 mov ecx,eax; --, ecx = 50 ...
my_proc: ; adr 25 <- stack push ebp ; {ebp} adr 25 mov ebp,esp; {ebp} adr 25 <-- now ebp points to {ebp} mov eax,[ebp+8]; [ebp]->{ebp},[ebp+4]->adr, [ebp+8]->25 (=param) add eax,eax; eax=25+25=50 mov esp,ebp; esp restored as at start of proc pop ebp; ebp restored, stack: adr 25 ret 4; return: pops adr from stack and removes 4 bytes from stack
|
when you use "proc" macro, it adds some high level-like work:
| CODE | ... ; -- <- stack ;push 25 ; 25 ;call my_proc ; 25 invoke my_proc,25; do same as code above mov ecx,eax; --, ecx = 50 ...
proc my_proc,x_param ;push ebp ; \ ;mov ebp,esp; -- this code added automatically by "proc" keyword
mov eax,[x_param]; "x_param" is automatically replaced with "ebp+8" ;mov eax,[ebp+8]
add eax,eax
ret ;mov esp,ebp; \ ;pop ebp; >-- this all automatically replaced with "ret" inside "proc" ;ret 4; /
endp |
finally, instead of "mov esp,ebp/pop ebp" the "leave" command is using, which does the same. the manner of such parameters transfer through stack is calling "procedure frame".
slightly similar is creating local variables for procedure in stack, which are as temporal, as parameters.
|