What is the purpose of the calling convention?

The calling convention states how arguments (parameters) are passed to a function and how the caller receives a return value. Amont others, the convention regulates if those values are passed via CPU registers and/or via the stack and which registers are guaranteed to preserve their values accross function calls.

What is EBP register?

A frame pointer (the ebp register on intel x86 architectures, rbp on 64-bit architectures) contains the base address of the function’s frame. The code to access local variables within a function is generated in terms of offsets to the frame pointer.

What does RETQ do in assembly?

The retq instruction pops the return address from the stack into the destination %rip , thus resuming at the saved return address.

What is C++ call convention?

A calling convention describes how the arguments are passed and values returned by functions. It also specifies how the function names are decorated. Is it really necessary to understand the calling conventions to write good C/C++ programs? Inside the function, registers ESI, EDI, EBX, and EBP are saved on the stack.

What is __ Fastcall in C++?

The __fastcall calling convention specifies that arguments to functions are to be passed in registers, when possible. This calling convention only applies to the x86 architecture. Called function pops the arguments from the stack.

What is the __stdcall calling convention in C++?

The __stdcall calling convention is used to call Win32 API functions. The callee cleans the stack, so the compiler makes vararg functions __cdecl. Functions that use this calling convention require a function prototype.

What is the difference between __stdcall and __cdecl?

__cdecl is the default calling convention for C and C++ programs. Because the stack is cleaned up by the caller, it can do vararg functions. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code.

What happens when you call a function from a __cdecl?

If you call a __stdcall function from a __cdecl, the __stdcall function cleans up the arguments on the stack, and then the __cdecl function does it again, possibly removing the calling functions return information. The Microsoft convention for C tries to circumvent this by mangling the names.

What is the calling convention for methods in a DLL?

This calling convention is used to call methods on classes exported from an unmanaged DLL. This member is not actually a calling convention, but instead uses the default platform calling convention. For example, on Windows x86 the default is StdCall and on Linux x86 it is Cdecl.