summaryrefslogtreecommitdiff
path: root/source/c-calling-conventions.rst
blob: ffed8fa877a9e611579ae7a66cc79f5b12b1a457 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#####################
C calling conventions
#####################

cdecl (Windows X86)
-------------------

Subroutine arguments are passed on the stack.

Integer values and memory addresses are returned in the EAX register

Registers EAX, ECX, and EDX are caller-saved, and the rest are callee-saved. [#wiki-call-conv]_

Other
-----

GCC keeps stack aligned to 16 bytes because called function may be SSE2 instruction that requires alignment to 16 bytes. [#gcc-stack-alignment]_

Footnotes
---------

.. [#wiki-call-conv] https://en.wikipedia.org/wiki/X86_calling_conventions
.. [#gcc-stack-alignment] `StackOverflow: why does the compiler subtract value on ESP <https://stackoverflow.com/q/38128940>`_