Calling Conventions

Two common x86 calling conventions are cdecl/syscall for 32-bit and System V AMD64 ABI for 64-bit.

  1. cdecl uses the stack-based approach; function arguments are pushed on the stack in the right-to-left order.

  2. The System V ABI passes function parameters first in registers and then on the stack.

    • For i386 (32-bit), function arguments are passed on the stack in reverse order such that the first argument is the last value pushed to the stack.

    • For x86-64 (64-bit), function arguments are passed to rdi, rsi, rdx, rcx, r8, and r9. If more arguments are required, they are pushed onto the stack in reverse order like the 32-bit version.

    • When a syscall is performed, the syscall number is in eax/rax.

    • In both syscalls and function calls, the return value is stored in eax/rax.

Last updated