The System V ABI

Integer arguments

The System V ABI passes integer arguments in RDI, RSI, RDX, RCX, R8, R9, then the stack, right to left. Floating-point arguments go in XMM0-XMM7, then the stack. The return value is in RAX, or XMM0 for floats:

; f(a, b, c) -> rdi=a, rsi=b, rdx=c, rax=result

Callee-saved

RBX, RBP, and R12-R15 belong to the caller: a callee that uses them must save and restore them. RAX, RCX, RDX, RSI, RDI, R8-R11 are caller-saved: the caller cannot expect them to survive a call.

The red zone

The 128 bytes below RSP are the red zone: leaf functions may use it for locals without adjusting RSP, because signal handlers do not touch it on Linux and macOS. Windows has no red zone, so Windows code always reserves stack explicitly.

Next: Makefiles for assembly

Article author: Arthur Isaev

Banner image