The Fetch-Execute Cycle
A CPU only really does one thing, over and over, billions of times a second: fetch an instruction from memory, work out what it means, and carry it out. Below is a genuinely wired simulation, watch data actually travel along the address bus and data bus, not just a list of registers changing.
The CPU's components
Registers are tiny, extremely fast storage locations inside the CPU, each with one specific job. The Control Unit and ALU aren't registers, but they're just as central to the cycle.
| Component | Full name | Job |
|---|---|---|
| PC | Program Counter | Holds the address of the next instruction to fetch |
| MAR | Memory Address Register | Holds the address currently being read from or written to |
| MDR | Memory Data Register | Holds the data just fetched from (or about to be written to) memory |
| CIR | Current Instruction Register | Holds the instruction currently being decoded and executed |
| CU | Control Unit | Decodes instructions and generates the signals that coordinate every other component |
| ALU | Arithmetic Logic Unit | Carries out calculations (add, subtract) and comparisons |
| ACC | Accumulator | Holds the running result of calculations |
Watch a real program run, wire by wire
This uses the same simplified instruction set taught in Little Man Computer: LDA (load), ADD, SUB, STA (store), HLT (halt). Pick a program, then step through it, watching exactly which wire lights up at each micro-step.
Program
Main memory (RAM)
The general algorithm
Controls
An instruction is just a binary number
Nothing magic is happening inside CIR: each instruction is stored as one ordinary byte, split into two halves, exactly the same idea as the number representation work you've already covered.
| Instruction | Opcode (4 bits) | Meaning |
|---|---|---|
| HLT | 0000 | Stop execution |
| LDA n | 0001 | ACC ← memory[n] |
| ADD n | 0010 | ACC ← ACC + memory[n] |
| SUB n | 0011 | ACC ← ACC − memory[n] |
| STA n | 0100 | memory[n] ← ACC |
Example: LDA 4 is opcode 0001 (LDA) plus operand 0100 (address 4), giving the single byte 00010100, or 0x14 in hex. The first 4 bits say what to do, the last 4 say which address.
Clock speed: how fast the cycle repeats
Clock speed, measured in Hz, is how many times per second the CPU can step through this cycle. A higher clock speed generally means more instructions completed every second.
Clock speed
Exam tips
- Clock speed alone doesn't tell the whole story: number of cores (separate processing units working in parallel) and cache size (fast memory built into the CPU) both also affect real-world performance.
- A single "instruction" in a real CPU can take several clock cycles, as this simulation shows: LDA, ADD, SUB and STA all need a second memory access during execute to actually read or write their operand.
- Clock speed is measured in Hertz (Hz): 1 Hz is 1 cycle per second. Modern CPUs run at gigahertz (GHz), billions of cycles per second.