General vs. Special Registers
Registers & Instruction Sets · Foundations track
3 min read
In this module
Two Kinds of Registers
Not all registers are equal. Some are general-purpose workhorses that hold whatever data the program needs. Others have a specific job baked into the hardware. The distinction matters for reading assembly code and reasoning about how programs actually execute.
General-Purpose Registers
These are the registers available for everyday use. A program can load values into them, do arithmetic on them, and store results back. Depending on the architecture, they might be named R0 through R7, or carry letters like EAX, EBX, ECX on x86 processors.
How many general-purpose registers you get varies by architecture. A simple teaching CPU might give you 8. 32-bit ARM has 13 general-purpose registers (R0-R12, with R13-R15 reserved for SP, LR, PC). 64-bit ARM (AArch64) has 31 general-purpose registers (X0-X30). x86-64 has 16 (RAX to R15), though that count includes RSP, the stack pointer, and RBP, which code often keeps as a frame pointer. More registers means the CPU can juggle more values without constantly hitting memory.
Special-Purpose Registers
A handful of registers carry dedicated roles the hardware depends on:
-
Program Counter (PC) holds the memory address of the next instruction to fetch. After each fetch, the PC auto-increments. Jump and branch instructions modify the PC to redirect the flow of execution.
-
Stack Pointer (SP) points to the top of the call stack. The stack is where return addresses, local variables, and saved register values get stored when calling functions. Push and pop operations adjust the SP automatically.
-
Flags Register carries the status bits the ALU sets after arithmetic and logic operations: zero, carry, overflow, sign. Not every instruction touches them (an x86
movdoesn't, and most ARM instructions only do when you ask with anSsuffix). Conditional branch instructions consult these flags to decide whether to jump. -
Instruction Register (IR) holds the instruction currently being decoded and executed. You don't touch the IR from your program; the control unit manages it entirely.
General-purpose registers store whatever data your program needs. Special-purpose registers like the Program Counter, Stack Pointer, Flags Register, and Instruction Register have fixed roles that the CPU hardware depends on to function correctly.
Why This Matters
When you write or read assembly language, most of the work is shuffling data between general-purpose registers, doing operations on them, and occasionally poking at special registers through specific instructions (a CALL instruction, for example, pushes the PC onto the stack). Knowing which registers exist and what they do is the first step toward understanding how software really talks to hardware.
You can watch the PC and SP cooperate in the simulator below. Step to the CALL and look at three things at once: the PC jumps to the double routine, SP drops from 0xFF to 0xFE, and the return address (4, the address of the instruction after the CALL) appears at memory address 0xFE. Step on to RET and the CPU reads that 4 back into the PC and moves SP back up, so execution carries on where it left off.
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 |
Pipeline
Cycle 0Notice that RET doesn't wipe the 4 from memory. It just moves SP past it. The stack module will show why that leftover data matters.