X86-assembly/High-level-logic/functions
Jump to navigation
Jump to search
You are here: | functions
|
Function anatomy
A function can be divided into 3 parts:
push ebp ; Save EBP
mov ebp, esp ; Save ESP in EBP
push ecx ; Allocate space for local variables
-------------------------------------------------------------
mov eax, [ebp+8] ;
add eax, [ebp+0Ch] ; Parameters passed to the function
add eax, [ebp+10h] ;
mov [ebp-4], eax ; Save result in local variable
mov eax, [ebp-4] ; Copy the result to EAX
-------------------------------------------------------------
mov esp, ebp ; Restore ESP
pop ebp ; Restore EBP
retn ; Return
|
|
Calling conventions
cdecl
Example: push offset aSet_me_0 ; "set_me"
push offset byte_40E024 ; Dest
call strcpy
add esp, 8 ; stack cleanup
|
stdcall
Example: push offset LibFileName ; "kernel32.dll"
call LoadLibraryA
mov [ebp+hLibModule], eax
|
fastcall
Example: push esi
push ebx
call sub_401020
add esp, 8
|
thiscall
Example: mov ecx, [ebp+var_8] ; ecx holds address of 'self'
call sub_41100A
|