What Are Registers?
Registers & Instruction Sets · Foundations track
3 min read
In this module
The Fastest Storage You Have
Registers are tiny storage locations built directly into the CPU. They hold the data the processor is actively working with: the numbers being added, the address of the next instruction, the result of the last comparison. Accessing a register takes less than a single nanosecond.
Why Not Just Use RAM?
RAM is huge. Modern computers have gigabytes of it. But RAM is also a long way from the CPU, electrically speaking. A round trip to main memory can take 50 to 100 nanoseconds or more. That sounds small in human terms; at 3 GHz the CPU can tick through 150 to 300 cycles in that window. Waiting that long for every byte would grind performance into the ground.
Registers solve this by keeping a small amount of data right where the CPU needs it, on the chip itself, wired directly to the ALU and control unit. The tradeoff is capacity. A typical CPU has somewhere between 8 and 32 general-purpose registers, each holding just one word of data (32 or 64 bits depending on the architecture). An x86-64 chip has 16, named rax through r15; a 64-bit ARM chip has 31, x0 to x30.
Registers are the fastest form of storage in a computer. They live inside the CPU and can be accessed in a fraction of a nanosecond. The tradeoff is that there are very few of them, typically 8 to 32 general-purpose registers.
The Speed Hierarchy
Registers sit at the top of what's called the memory hierarchy:
- Registers are the smallest and fastest. Inside the CPU.
- Cache (L1, L2, L3) is larger and slightly slower. Still on or next to the CPU chip.
- RAM is much larger, much slower.
- Disk / SSD is enormous, but orders of magnitude slower than RAM.
Here's the same ladder with rough numbers attached. They're typical figures for a current desktop or laptop and vary between chips, so treat them as orders of magnitude rather than specs:
Look at the jump between the last two boxes. An SSD read takes roughly a thousand times longer than a RAM read, and a RAM read takes around a hundred times longer than a register access.
Every level trades speed for capacity. Programs run fastest when the data they need is already in a register. A large part of what compilers and CPU designers do is keep the right data in registers at the right time.
What Registers Look Like
A register is a small group of flip-flops, the same kind of one-bit memory circuits you'd build from logic gates. Line up 32 flip-flops and you have a 32-bit register that can hold one integer, one memory address, or one instruction. Simple in concept, indispensable in practice.
The simulator below shows the eight general-purpose registers (R0 to R7) of a small teaching CPU, plus its special ones. Press Step and watch R0 take the value 5, then R1 copy it, then R1 grow to 12. Nothing outside the register panel changes, because none of these instructions touches memory.
For the best simulation experience, use a desktop browser.
Assembly
Registers
ALU
Memory
| Address | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 10 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 20 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 30 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 40 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 50 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 60 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 70 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 80 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| 90 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| A0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| B0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| C0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| D0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| E0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
| F0 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |