Level 0 · Module 1
CPU instruction cycle
Trace how a processor fetches, decodes, executes, and records an instruction.
Not completed
By the end, you can
- List the core stages of an instruction cycle.
- Trace a simple arithmetic instruction through those stages.
- Explain why the cycle repeats many times per second.
Summary
At a high level, a CPU repeatedly gets an instruction, works out what it means, carries it out, and stores any result. Then it chooses the next instruction and repeats.
Introduction
Programs can look like one large, continuous action: “open a photo” or “add a score.” A processor handles them as a precisely ordered stream of tiny steps. It repeats this cycle billions of times each second.
Explanation
The CPU starts with a program counter, a small value that points to the next instruction. During fetch, it reads that instruction from memory. During decode, it works out the instruction’s action and data. During execute, it performs the action, such as adding two values. During write back, it records a result in a register or memory when there is one to record. Finally, it chooses where to fetch next. Usually it moves forward, but a jump instruction can choose a different address.
Real-world example
The game code loads the current score, adds the points earned, stores the new score, and continues. Each source-level statement may become several instruction cycles.
One instruction, four stages
Interactive exploration
Fetch, decode, execute
Step 1 of 4
- fetch
- decode
- execute
- write back
PC → 104
The program counter is the CPU’s bookmark: it identifies where to fetch next. Usually it moves forward after an instruction. A jump or conditional branch can change it, which lets programs make choices and repeat work.
Code example
1. fetch instruction at programCounter
2. decode operation and operands
3. execute add R1 and R2
4. write result to R1Common mistakes
- Treating fetch and decode as the same task.
- Assuming every instruction writes a result; a comparison or jump may primarily change control flow.
- Thinking the CPU reads a full application into itself at once.
Quiz
Knowledge check
Try it
Trace an increment
For a hypothetical ADD counter, 1 instruction, write one short sentence for fetch, decode,
execute, and write back.
Key takeaways
- Fetch, decode, execute, and write back form a useful CPU-cycle model.
- The program counter helps select the next instruction.
- Complex programs emerge from enormous numbers of small repeated cycles.