24 min read
The Fetch–Decode–Execute Cycle
Step through how the CPU fetches an instruction, works out what it means and carries it out — billions of times a second.
The Cycle
The CPU does one thing again and again: it fetches an instruction from memory, decodes it to find out what to do, and executes it. This is the fetch–decode–execute cycle (also called the instruction cycle or machine cycle).
1. Fetch
- The address in the PC is copied into the MAR.
- The address travels along the address bus; the control unit sends a READ signal on the control bus.
- The instruction at that address travels along the data bus into the MDR.
- The instruction is copied from the MDR into the CIR.
- The PC is increased by 1, so it points to the next instruction.
2. Decode
The control unit reads the instruction in the CIR and splits it into two parts:
- the opcode — what to do (for example LOAD, ADD, STORE),
- the operand — what to do it to (often a memory address).
3. Execute
The instruction is carried out. For example, ADD 6 fetches the value at address 6 and the ALU adds it to the accumulator. Then the cycle starts again with the next fetch.
Step through the fetch–decode–execute cycle
CPU registers
PC — program counter
0
MAR — memory address
—
MDR — memory data
—
CIR — current instruction
—
ACC — accumulator
0
Main memory (RAM)
| Address | Contents |
|---|---|
| 0 | LOAD 5 |
| 1 | ADD 6 |
| 2 | STORE 7 |
| 3 | HALT |
| 4 | |
| 5 | 12 |
| 6 | 30 |
| 7 | 0 |
The program in memory adds two numbers (at addresses 5 and 6) and stores the answer at address 7. Press Next to start.
An Everyday Analogy
Practice
Choose all that apply.
More lessons in Computer Hardware and Peripherals · Next: What Makes a Processor Faster · Previous: Buses: Data, Address and Control
