Calling Conventions

In computer science, a calling convention is an implementation-level (low-level) scheme for how subroutines receive parameters from their caller and how they return a result. Differences in various implementations include where parameters, return values, return addresses and scope links are placed (registers, stack or memory etc.), and how the tasks of preparing for a function call and restoring the environment afterwards are divided between the caller and the callee.

The Well-known calling conventions are:

  • __cdecl

  • __stdcall

  • __fastcall

In the first two calling conventions, the parameters of the function are pushed onto the stack in reverse order. For Example: if there is a function "void myFunction(int a,int b)".The function will be assembled as:-

push b
push a
call myFunction
push a
push b
call MyFunction
test eax, eax
je _somewhere
mov esp,ebp 
pop ebp
ret 8 <- cleanup the stack from paramenters a and b

__cdecl

push a
push b
Call MyFunction
add esp, 8
test eax, eax

Last updated