CPU in slow motion

Watch what a CPU really does with every instruction. Each step is computed by a simulator as you go, not played back from a recording.

Assembly guide

How to read this page

  1. 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.
  2. Press Next step and read the sentence under the buttons. Watch the registers: they really change.
  3. 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.

  1. 1Fetch
  2. 2PC + 1
  3. 3Decode
  4. 4Execute
  5. 5Write-back

Program

Instructions are read from here, not from the cache. Reading them is free. What do these instructions mean?

  1. 0LOAD R1, [4]next

    Read memory cell 4 into R1

  2. 1LOAD R2, [5]

    Read memory cell 5 into R2

  3. 2ADD R1, R2

    R1 = R1 + R2

  4. 3STORE 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

R0

0

R1

0

R2

0

R3

0

ALU

Idle

Arithmetic 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.

Slot 0

empty

Slot 1

empty

Slot 2

empty

Slot 3

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.

0x00
0x04
0x08
0x0C
0x10
0x14
0x18
0x1C
0x20
0x24
0x28
0x2C
0x30
0x34
0x38
0x3C

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

Check the simulator (self-test)