Table of Contents
IronForgeCyber
Courses
Resources
Blog
Log In


IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. asm-101
  3. registers
4 min read

Registers

A register is a tiny, extremely fast storage slot built into the CPU itself. Where C variables live somewhere in memory, the values a program is actively working on live in registers — reading one is effectively free, while reaching out to memory is comparatively slow. Almost every instruction you write names a register, so these sixteen slots are the vocabulary of assembly.

What a Register Is

Each general-purpose register on x86-64 holds 64 bits. There is no type — a register is just 64 bits that an instruction interprets as a number, an address, a character, or a bit pattern, depending on what the instruction does. Think of them as the CPU's working set: load values in, operate, write results back out to memory when you are done.

The General-Purpose Registers

There are sixteen: rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, and r8 through r15. Each can also be accessed at narrower widths through aliased names that refer to the same underlying bits — the low 32, low 16, or low 8:

64-bit32-bit16-bit8-bit
raxeaxaxal
rbxebxbxbl
rcxecxcxcl
rdxedxdxdl
rsiesisisil
rdiedididil
r8r8dr8wr8b

The older registers (rax–rdi) carry historical names from the 16-bit era; the newer ones (r8–r15) use the uniform d/w/b suffixes. Writing al changes only the lowest byte of rax and leaves the rest untouched — a fact with a sharp edge, below.

Special Registers

A few registers have dedicated jobs:

  • rip — the instruction pointer, the address of the next instruction to execute. You never write it directly; jumps, calls, and returns do.
  • rsp — the stack pointer, which always points at the top of the stack.
  • rbp — the base pointer, conventionally used to anchor a function's stack frame.
  • rflags — the status flags, individual bits set as a side effect of instructions: ZF (zero), SF (sign), CF (carry), and OF (overflow) are the ones that drive conditional jumps.

Caller vs. Callee Registers

When one function calls another, they need an agreement about who is allowed to overwrite which registers — otherwise every call would destroy the caller's working values. The System V AMD64 ABI (what Linux uses) splits the registers into two groups:

GroupRegistersRule
Caller-saved (volatile)rax, rcx, rdx, rsi, rdi, r8–r11A called function may freely clobber these. If the caller needs them after the call, it must save them first.
Callee-saved (preserved)rbx, rbp, r12–r15A called function must leave these exactly as it found them — saving and restoring any it uses.

The practical takeaway: after a call, do not assume a caller-saved register still holds what you put there — the callee was allowed to trash it. This convention is also why function arguments go in specific registers (rdi, rsi, rdx, rcx, r8, r9), which we cover with the stack and calls.

Sub-register Aliasing

Writing a 32-bit register zeroes the top 32 bits of the full register. Writing a 16- or 8-bit register does not — it leaves the upper bits alone.

This is the single most surprising register rule, so watch it happen. Stepping through a program that sets rax to all-ones and then writes eax, versus setting rbx to all-ones and writing bl:

gdb
gef➤ break _startBreakpoint 1 at 0x401000gef➤ runBreakpoint 1, 0x0000000000401000 in _start ()gef➤ si0x0000000000401007 in _start ()gef➤ p/x $rax$1 = 0xffffffffffffffffgef➤ si0x000000000040100c in _start ()gef➤ p/x $rax$2 = 0x1gef➤ si0x0000000000401013 in _start ()gef➤ p/x $rbx$3 = 0xffffffffffffffffgef➤ si0x0000000000401015 in _start ()

After mov eax, 0x1, rax is 0x1 — the upper 32 bits were wiped. But after mov bl, 0x42, rbx is 0xffffffffffffff42 — only the lowest byte changed. Forgetting the 32-bit case (expecting leftover high bits that are actually gone) and forgetting the 8-bit case (expecting a clean value when garbage lingers up top) are both common bugs.

gef➤ p/x $rbx
$4 = 0xffffffffffffff42