Calling convention

The calling convention is a set of rules that defines how functions are called and how arguments are passed between functions in a program. The calling convention specifies the order in which arguments are passed to a function, the location where the return value is stored, and other details that are necessary for functions to communicate with each other.

On the x86 architecture, there are several different calling conventions that are used, depending on the operating system and the type of function being called. Some of the most commonly used calling conventions on the x86 architecture include:

  • cdecl: This calling convention is used for functions written in C or C++. It is the default calling convention on the x86 architecture. In this convention, arguments are passed to the function on the stack, and the caller is responsible for cleaning up the stack after the function returns.

  • stdcall: This calling convention is also used for functions written in C or C++. It is similar to the cdecl convention, but the callee is responsible for cleaning up the stack after the function returns. This calling convention is often used for functions that are exported from dynamic link libraries (DLLs).

  • fastcall: This calling convention is an optimization of the cdecl convention. It is used for functions that are called frequently and that do not take many arguments. In this convention, the first two arguments are passed in registers, and any additional arguments are passed on the stack.

  • thiscall: This calling convention is used for member functions in C++ classes. It is similar to the stdcall convention, but the this pointer is passed in the ECX register rather than on the stack.

Overall, the x86 architecture supports a wide range of calling conventions, which allows it to be used in a variety of programming languages and environments.

Last updated