Most commons are cdecl, stdcall, fastcall
In function calls, parameters are pushed onto the stack from right to left.
int func(int x, int y, int z, int m, int k);
int a, b, c, d, e, ret;
ret = func(a, b, c, d, e);
- C declaration
- uses stack frame
- The caller cleans up the stack
push e
push d
push c
push b
push a
call func
add esp, 20 ; cleaning up the stack. 5 integer parameters --> 4-bytes x 5 = 20
- Standart call
- used by Windows API
- uses stack frame
- callee cleans up the stack
push e
push d
push c
push b
push a
call func
; callee cleans up the stack so no need to add esp, 20
- uses registers(for first few instructions) and stack frame
- callee cleans up the stack
ecx, edx
(32-bit)(Microsoft)rcx, rdx, r8, r9
(64-bit)(Microsoft, Intel)- left-to-right for registers
- right-to-left for stack
mov ecx, a
mov edx, b
push e
push d
push c
call func
; for x64
mov rcx, a
mov rdx, b
mov r8, c
mov r9, d
push e
call func