Registers and Data Sizes
Registers are the fastest storage your computer has. They sit inside the CPU itself, accessible in a single clock cycle — orders of magnitude quicker than RAM. x86-64 gives you 16 general-purpose registers, 64 bits wide each, plus a handful of special-purpose registers that steer how the processor behaves.
Every assembly operation either reads from or writes to them. This is your workspace; learn it.
For a deeper dive into register architecture, see x86 Registers.
The 16 General-Purpose Registers
x86-64 provides these 16 general-purpose registers:
| Register | Traditional Use | Callee-saved? |
|---|---|---|
rax | Return value, accumulator | No |
rbx | Base register | Yes |
rcx | Counter (loop operations) | No |
rdx | Data, I/O, multiply/divide extension | No |
rsi | Source index for string operations | No |
rdi | Destination index for string operations | No |
rsp | Stack pointer | Yes |
rbp | Base/frame pointer | Yes |
r8 | General purpose | No |
r9 | General purpose | No |
r10 | General purpose | No |
r11 | General purpose | No |
r12 | General purpose | Yes |
r13 | General purpose | Yes |
r14 | General purpose | Yes |
r15 | General purpose | Yes |
The first eight (rax through rbp) are descendants of the original x86 set. AMD bolted on r8 through r15 when they stretched the architecture to 64 bits.
While all 16 registers can hold arbitrary data, many have implicit uses baked into the instruction set. For example, rcx is the implicit counter for loop and rep instructions, rax holds the return value from functions and syscalls, and rsp always points to the top of the stack. You can use them for other things, but you must be aware of instructions that read or modify them implicitly.
Register Sub-Parts
Each 64-bit register can also be poked at smaller widths. That's the fossil record of x86 climbing from 16-bit to 32-bit to 64-bit:
For rax through rsp:
- 64-bit:
rax,rbx,rcx,rdx,rsi,rdi,rsp,rbp - 32-bit (lower half):
eax,ebx,ecx,edx,esi,edi,esp,ebp - 16-bit (lower quarter):
ax,bx,cx,dx,si,di,sp,bp - 8-bit low:
al,bl,cl,dl,sil,dil,spl,bpl - 8-bit high (first four only):
ah,bh,ch,dh
For r8 through r15, the naming pattern is:
- 64-bit:
r8,r9, ...r15 - 32-bit:
r8d,r9d, ...r15d - 16-bit:
r8w,r9w, ...r15w - 8-bit:
r8b,r9b, ...r15b
Open the bit visualizer below to watch a value shift shape across the different register widths:
Writing to a 32-bit register (like eax) automatically zeros the upper 32 bits of the full 64-bit register. This is by design - it avoids partial register dependencies. However, writing to 16-bit or 8-bit sub-registers does NOT zero-extend. This inconsistency is a common source of bugs: mov al, 5 modifies only the lowest byte and leaves the upper 56 bits of rax unchanged, but mov eax, 5 zeros the upper 32 bits.
Special-Purpose Registers
Three registers come with dedicated jobs you can't repurpose:
rip (Instruction Pointer) holds the address of the next instruction. You don't write to it via mov; it advances on its own and shifts when jumps, calls, or returns execute.
rsp (Stack Pointer) points at the top of the stack. Technically general-purpose, but use it for anything else and your program crashes within microseconds.
rflags (Flags Register) is a 64-bit register whose individual bits record what just happened during the last arithmetic or logical operation. The ones you'll touch most:
| Flag | Bit | Meaning |
|---|---|---|
| CF (Carry) | 0 | Unsigned overflow occurred |
| ZF (Zero) | 6 | Result was zero |
| SF (Sign) | 7 | Result was negative |
| OF (Overflow) | 11 | Signed overflow occurred |
Data Sizes
x86-64 has its own vocabulary for data widths:
| Name | Size | Bits | NASM Directive | Register Example |
|---|---|---|---|---|
| byte | 1 byte | 8 | db | al |
| word | 2 bytes | 16 | dw | ax |
| dword (double word) | 4 bytes | 32 | dd | eax |
| qword (quad word) | 8 bytes | 64 | dq | rax |
For memory accesses, you usually have to spell out the size:
mov byte [rdi], 0 ; write 1 byte of zerosmov word [rdi], 0 ; write 2 bytes of zerosmov dword [rdi], 0 ; write 4 bytes of zerosmov qword [rdi], 0 ; write 8 bytes of zerosIn security contexts, registers can contain sensitive data from previous operations - encryption keys, passwords, or pointers to protected memory. When writing security-sensitive code, you should explicitly clear registers before returning from functions. A common pattern is xor eax, eax to zero a register (which zeros the full 64-bit rax via zero-extension). Failing to clear registers is a real vulnerability class in cryptographic implementations.
Practical Examples
; Loading different-sized valuesmov rax, 0xDEADBEEFCAFEBABE ; 64-bit immediate into raxmov eax, 0xCAFEBABE ; 32-bit, zeros upper 32 bits of raxmov ax, 0xBABE ; 16-bit, preserves upper 48 bitsmov al, 0xBE ; 8-bit, preserves upper 56 bits
; Common register operationsxor eax, eax ; zero rax (preferred: 2 bytes, opcode 31 c0, zeros full 64-bit rax via zero-extension; xor rax, rax requires a REX prefix and is 3 bytes)mov rcx, rdi ; copy rdi to rcxPredict the Register
Each line below starts fresh from mov rax, -1, so every bit of rax is set. Write down rax in hex after the second instruction, then open the answer.
mov rax, -1 ; then one of:mov eax, 5 ; (a)mov ax, 5 ; (b)mov al, 5 ; (c)mov ah, 5 ; (d)mov eax, eax ; (e)Answers
- (a)
0x0000000000000005. A 32-bit write zeroes the top half. - (b)
0xFFFFFFFFFFFF0005. Only bits 15-0 change. - (c)
0xFFFFFFFFFFFFFF05. Only bits 7-0 change. - (d)
0xFFFFFFFFFFFF05FF.ahis bits 15-8, so the 05 lands one byte up. - (e)
0x00000000FFFFFFFF. Copyingeaxonto itself looks like a no-op, but it's a 32-bit write, so it clears the upper half. Compilers use exactly this to zero-extend a 32-bit value.
What is Next
With the register file in your head, the next lesson digs into how assembly programs are organised into sections, and how NASM directives let you carve out data and structure your code.