Registers vs Memory
Part of the Fundamentals section of Coddy's Assembly journey — lesson 3 of 45.
You have now learned about two places where data can live inside a computer:
- Registers — tiny storage boxes inside the CPU
- Memory (RAM) — a giant grid of numbered slots outside the CPU
But why are there two places? Why can't the CPU just work directly with memory?
The answer is speed. Registers are extremely fast because they are inside the CPU. Memory is slower because it is outside. The CPU can access a register in a single cycle, but accessing memory takes much longer.
Side-by-side comparison:
| Feature | Registers | Memory (RAM) |
|---|---|---|
| Location | Inside the CPU | Outside the CPU |
| Speed | Extremely fast (1 cycle) | Slower (many cycles) |
| Number of storage slots | Very few (16-32 on x86-64) | Millions or billions |
| Size of each slot | 8 bytes (64 bits) | 1 byte |
| How you access them | By name (rax, rbx, rcx...) | By address (1000, msg, buffer) |
| Volatile? | Yes (disappears when power off) | Yes (disappears when power off) |
The most important rule in assembly:
The CPU cannot work directly with data in memory. Data must be loaded into registers first.
This is not optional. It is how the CPU is designed. Every addition, every comparison, every move of data must go through a register.
The three-step pattern you will use constantly:
| Step | What happens | Example |
|---|---|---|
| 1. LOAD | Copy data from memory into a register | mov rax, [count] |
| 2. WORK | Do something with the register | add rax, 5 |
| 3. STORE | Copy the result back to memory (if needed) | mov [result], rax |
What happens if you forget this rule?
If you try to add two numbers that are both in memory, the assembler will give you an error. The CPU simply cannot do it. You must load them into registers first.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
1The Machine
What is CPUMemoryRegisters vs MemoryHow instructions workTwo-File PatternThe x86-64 Architecture