Programming/Calling conventions

From Sidvind
Jump to: navigation, search

x86[edit]

cdecl[edit]

  • Keyword: (MSVC _cdecl, GCC cdecl)
  • Compilers: Microsoft Visual C++, GCC

The cdecl calling convention is the standard convention for most x86 compilers. Arguments are pushed on the stack right to left. Return values are passed in EAX. The caller clean the stack.

Stdcall[edit]

  • Keyword: MSVC __stdcall, GCC stdcall
  • Compilers: Microsoft Visual C++, GCC

Like cdecl but the callee is cleaning the stack.

Fastcall[edit]

  • Keyword: MSVC __fastcall, GCC fastcall
  • Compilers: Microsoft Visual C++, GCC

The first two arguments are passed left to right in ECX and EDX. Remaining arguments are pushed onto the stack from right to left. The callee clean the stack.

Thiscall[edit]

Using MSVC, thiscall is similar to stdcall but the this pointer passed in ECX.

Using GCC, thiscall is similar to cdecl but the this pointer is pushed last onto the stack as if it would have been the first argument to the function.

x64[edit]

MIPS[edit]

The MIPS passes the first four arguments to a function in the registers $a0-$a3; subsequent arguments are passed on the stack. The return value (or a pointer to it) is stored in register $v0.