Teaching / Fetch–Execute cycle
Interactive lesson
The Fetch–Execute Cycle
A working Von Neumann computer you can take apart. Step through the cycle one register transfer at a time, change the program in memory, and see what the Control Unit, ALU and registers do. Then break it on purpose.
This page supports British University Vietnam students in the module Introduction to Computing Science (2024–2027 and onwards). It accompanies the Week 8 “Systems” lecture.
What’s the bug? (spoiler)
On a narrow screen, scroll the diagram sideways.
CPU
- Opcode
- —
- Operand
- —
- Instructions run
- 0
- A
- —
- B
- —
- Operation
- —
- Result
- —
- Zero flag
- —
Main memory 16 cells × 8 bits. Instructions and data share it.
| Address | Contents | Meaning (edit me) |
|---|
Type an instruction (LOAD 8, ADD 9, JZ 6, OUT, HLT) or a number
(25, 0b1010, 0x1F). The ▶ marks the PC. The CPU only ever sees bits.
Save / load a program as text
What is happening
Ready
Instruction 1: micro-steps
Bug watch 0
The computer never checks that your design makes sense. This panel points out what it silently did that you may not have meant.
No problems noticed yet.
Instruction trace Instructions: 0 · Memory accesses: 0
Every instruction needs at least one memory access to be fetched. LOAD, STO, ADD and the rest need another. All of it goes through one bus: the Von Neumann bottleneck.
| # | Cell | Instruction | Effect |
|---|
Nothing has run yet.
Instruction set of this machine
Each instruction is one 8-bit word: the top 4 bits are the opcode, the bottom 4 bits are the operand (usually an address). Cells holding 0 decode as HLT. Opcodes 11–15 do not exist.
| Opcode | Mnemonic | Effect | Notes |
|---|
Things to try
- Predict, then check. Load the lecture example. Before each instruction, write down what ACC and memory will hold afterwards.
- Change the operands. Edit
ADD 5toSUB 5in the lecture example. What is 101 − 143 in 8 bits? - Execute data. Set Start PC to 4 so the CPU fetches the number 101. Which instruction is
0110 0101? Remember: the “As code” column shows how the CPU would read every data cell. - Design a program. Use Blank memory to compute (a + b) − c, or to double a number, and print the answer.
- Diagnose the five bugs in the Bugs to diagnose group. Run each, find what went wrong from the Bug watch and the trace, fix it by editing memory, and run it again.
- Count memory accesses. How many trips to memory does the multiplication program make? Why would a separate memory for instructions and data (the Harvard model) help?
- Break it your way. Press 🎲 Random memory and Run. Is a random program more likely to halt, fault or loop forever? Why?