64-bit Version
| Register | Purpose in Our Program | Why this specific register? |
|---|---|---|
| RAX | Holds the syscall number | Convention: First argument for syscalls |
| RDI | Holds file descriptor (stdout=1) | Syscall argument #1 |
| RSI | Holds address of the string | Syscall argument #2 |
| RDX | Holds length of the string | Syscall argument #3 |
| RDI | Holds exit code (used again) | Syscall argument #1 for exit |
These are part of the System V ABI (the standard calling convention on Linux 64-bit).
32-bit Version (The First One)
| Register | Purpose | Why? |
|---|---|---|
| EAX | Syscall number | Old convention |
| EBX | File descriptor / Exit code | Old convention |
| ECX | Address of string | Old convention |
| EDX | Length of string | Old convention |
Quick Summary: Why These Registers?
- In 32-bit (old way): Linux used EAX, EBX, ECX, EDX in that order for system calls.
- In 64-bit (new way): Linux uses RAX, RDI, RSI, RDX, R10, R8, R9 in that order.
This is not random — it’s a standard agreement between the kernel and programs so the operating system knows where to find the parameters.
General Purpose Registers (64-bit)
You will see these often:
- RAX, RBX, RCX, RDX → General workhorses
- RDI, RSI → Often used for strings / function arguments
- RBP, RSP → Base pointer and Stack pointer
- R8–R15 → Extra general registers
