Registers

General purpose

x86-64 has sixteen 64-bit general-purpose registers: rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, and r8 through r15. Any of them can hold any integer value in most instructions.

mov rax, 100 ; any register works mov r8, 200 ; r8-r15 are 64-bit too mov r15b, 1 ; the lowest 8 bits of r15

Traditional roles

Some registers have traditional roles: rax holds return values, rcx and rdx hold multiplication and division results, rsi and rdi index string operations, rbp points at the stack frame, and rsp tracks the top of the stack.

mov rax, 6 ; sys_exit number goes in rax mov rdi, 0 ; exit status goes in rdi

Register widths

Each 64-bit register has narrower views: the low 32 bits (eax), low 16 (ax), and low 8 (al and ah). Writing a 32-bit register zero-extends into the 64-bit one:

mov eax, 1 ; rax becomes 0x0000000000000001 mov ax, 0xFFFF ; only the low 16 bits change

Next: MOV and data transfer

Article author: Arthur Isaev