Skip to content

Instantly share code, notes, and snippets.

@jxu
Last active September 6, 2024 20:13
Show Gist options
  • Save jxu/5fdc1bbf32b95374e75bce479f3559c7 to your computer and use it in GitHub Desktop.
Save jxu/5fdc1bbf32b95374e75bce479f3559c7 to your computer and use it in GitHub Desktop.

x86-32 cdecl

Arguments pushed on stack, right-to-left.

Caller-saved: eax, ecx, edx. All others are callee-saved.

Return value in eax.

General purpose registers:

  1. EAX (Accumulator)
  2. EBX (Base): pointer to data
  3. ECX (Counter): shift/rotate instructions and loops
  4. ESP (Stack Pointer)
  5. EBP (Stack Base Pointer)
  6. EDI (Destination Index)
  7. ESI (Source Index Register)
  8. EDX (Data): arithmetic and I/O

x86-32 GCC fastcall

Like cdecl but first two arguments in ecx, edx

x86-32 Linux registers (root/arch/x86/entry/calling.h)

Arguments (callee-clobbered): eax, edx, ecx

Extra callee-clobbered: None

Callee-saved: ebx, edi, esi, ebp

Return: eax (, edx)

x86-64 SysV (Linux)

Arguments in order: rdi, rsi, rdx, rcx, r8, r9.

Callee saved: rbx, rsp, rbp, r12-r15 (if callee doesn't use these, nothing needs to be saved). All others are caller-saved.

Return value in rax.

Custom calling convention

Do whatever you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment