32-bit vs 64-bit

Registers

32-bit x86 has eight general-purpose registers (EAX through EDI); x86-64 has sixteen (RAX through R15). The extra registers are the biggest single reason 64-bit code runs faster: fewer memory spills.

mov eax, 1 ; 32-bit: 8 registers mov rax, 1 ; 64-bit: 16 registers

Syscall interface

32-bit Linux uses INT 80h with the call number in EAX and arguments in EBX, ECX, EDX, ESI, EDI, EBP. 64-bit Linux uses SYSCALL with RAX and RDI, RSI, RDX, R10, R8, R9. The numbers differ too: exit is 1 in 32-bit, 60 in 64-bit.

Calling conventions

32-bit C pushed all arguments on the stack (cdecl). 64-bit System V passes the first six in registers. So a 64-bit call is faster, and an argument list that fit fine in 32-bit registers can spill to the stack in either world.

Questions

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

  1. How many general-purpose registers does 32-bit x86 have?

    Answer

    8

    EAX through EDI are eight registers; x86-64 adds eight more.

  2. How many general-purpose registers does x86-64 have?

    Answer

    16

    RAX through R15 are sixteen registers, and R8-R15 are the new ones.

  3. Which registers carry 32-bit Linux syscall arguments?

    Answer

    EBX, ECX, EDX, ESI, EDI, EBP

    The int 0x80 interface uses EBX and the other 32-bit registers; the call number is in EAX.

  4. Which register holds the 32-bit syscall number?

    Answer

    EAX

    The 32-bit path selects the call with EAX, and the arguments start at EBX.

  5. What is the exit syscall number in 32-bit Linux?

    Answer

    1

    The 32-bit exit is 1; the 64-bit exit is 60 and exit_group is 231.

  6. How does 32-bit cdecl pass function arguments?

    Answer

    On the stack

    The caller pushes the arguments, and the callee reads them from the stack.

  7. How does the 64-bit System V ABI pass the first six integer arguments?

    Answer

    In RDI, RSI, RDX, RCX, R8 and R9

    Registers carry the first six, and only the rest go on the stack.

  8. What exit status does this 64-bit program return? section .text global _start _start: mov rax, 60 mov rdi, 42 syscall

    Answer

    42

    The 64-bit exit takes the status in RDI, and it is 42 here.

  9. Why does 64-bit code often need fewer memory spills?

    Answer

    It has twice as many registers

    Sixteen registers keep more values live without saving them to memory.

  10. Which instruction enters the kernel in 64-bit Linux?

    Answer

    syscall

    SYSCALL is the 64-bit path; int 0x80 is the older 32-bit interface.

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

Article author: Arthur Isaev