How to read this page
- A CPU runs a program one instruction at a time. Every instruction goes through the same five steps: Fetch, PC + 1, Decode, Execute, Write-back.
- Press Next step and read the sentence under the buttons. Watch the registers: they really change.
- Most instructions take 1 tick. Reading memory can take 100 ticks, unless the data is already on the Desk (the cache). Try switching the cache off at the end.
Ready. The CPU will run line 0 first: "LOAD R1, [4]" (Read memory cell 4 into R1). Press Next step and read this bar: it explains every move.
- 1Fetch
- 2PC + 1
- 3Decode
- 4Execute
- 5Write-back
Program
Instructions are read from here, not from the cache. Reading them is free. What do these instructions mean?
- 0
LOAD R1, [4]nextRead memory cell 4 into R1
- 1
LOAD R2, [5]Read memory cell 5 into R2
- 2
ADD R1, R2R1 = R1 + R2
- 3
STORE R1, [8]Write R1 into memory cell 8
CPU the part that runs the instructions
PC
Program counter: which line is next
0
IR
Instruction register: the instruction being run
(empty)
Registers tiny, instant storage
0
0
0
0
ALU
IdleArithmetic logic unit: does the maths
No maths job right now.
Control Unit
CU: reads the instruction and gives the orders
Waiting for an instruction.
Memory helper
LSU: fetches and saves data
Idle: no memory job.
Desk (cache) small and fast: 3 ticks
4 slots. Each slot holds one whole box of 4 cells. When full, the box used longest ago leaves.
empty
empty
empty
empty
Warehouse (RAM) big and slow: 100 ticks
64 cells in boxes of 4. The CPU never takes just one cell: it takes the whole box. Click a cell to change its value.
Ticks so far (one tick = one step of the CPU clock)
0
Where the ticks went
Waiting for memory: 0 ticks. Everything else: 0 ticks.
Desk results
Hits (found on the Desk): 0
Misses (walk to the Warehouse): 0