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.

Questions

A new set of questions in a new order every time. Choose one answer for each, then check.

  1. Where does the System V ABI pass the first integer argument?

    Answer

    RDI

    The six integer argument registers start at RDI.

  2. Where does the System V ABI pass the seventh integer argument?

    Answer

    On the stack

    Only six integer registers carry arguments; the rest go on the stack.

  3. Which register returns an integer value?

    Answer

    RAX

    RAX holds the return value, or XMM0 for a floating-point result.

  4. Which registers are callee-saved?

    Answer

    RBX, RBP, R12-R15

    A callee that uses these must restore them before it returns.

  5. What does caller-saved mean?

    Answer

    The caller must save them if it needs them after the call

    The callee may overwrite a caller-saved register freely.

  6. How large is the red zone below RSP?

    Answer

    128 bytes

    The 128 bytes below RSP are reserved for a leaf function on Linux and macOS.

  7. Which function may use the red zone?

    Answer

    A leaf function that calls nothing

    A call would push a return address into the red zone, so only a leaf function may rely on it.

  8. Which system has no red zone?

    Answer

    Windows x64

    Windows code always reserves its stack space explicitly.

  9. Where does a floating-point argument go?

    Answer

    XMM0-XMM7, then the stack

    The first eight floating-point arguments use the XMM registers.

  10. What must a callee do with RBP if it uses RBP as a frame pointer?

    Answer

    Save the old value and restore it before returning

    RBP is callee-saved, so the caller expects its value back.

The snippets on this page are fragments, not whole programs: they show the ABI rules. They were assembled with NASM 3.01 on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev