# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.ctfrecipes.com/pwn/architectures/x86-x64/calling-convention.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
