Calling Conventions: Difference between revisions

Add table of calling conventions
[unchecked revision][unchecked revision]
m (add syntaxhighlight tags)
(Add table of calling conventions)
Line 5:
==Basics==
As a general rule, a function which follows the C calling conventions, and is appropriately declared (see below) in the C headers, can be called as a normal C function. Most of the burden for following the calling rules falls upon the assembly program.
 
== Cheat Sheets ==
 
{| {{wikitable}}
! Platform
! Return Value
! Parameter Registers
! Additional Parameters
! Stack Alignment
! Scratch Registers
! Preserved Registers
|-
| System V i386 || eax, edx || none || stack || || eax, ecx, edx || ebx, esi, edi, ebp, esp
|-
| System V X86_64 || rax, rdx || rdi, rsi, rdx, rcx, r8, r9 || stack || 16-byte at call<sup>[[#Note1|1]]</sup> || rax, rdi, rsi, rdx, rcx, r8, r9, r10, r11 || rbx, rsp, rbp, r12, r13, r14, r15
|-
| ARM || r0, r1 || r0, r1, r2, r3 || stack || 8 byte<sup>[[#Note2|2]]</sup> || r0, r1, r2, r3, r12 || r4, r5, r6, r7, r8, r9, r10, r11, r13, r14
|}
 
<small id="Note1">Note 1: Stack is 16 byte aligned at time of call. The call pushes %rip, so the stack is 16-byte aligned again if the callee pushes %rbp.</small>
 
<small id="Note2">Note 2: Stack is 8 byte aligned at all times outside of prologue/epilogue of function.</small>
 
==External References==
Anonymous user