The loop every processor repeats: fetch an instruction from memory, decode its opcode and carry it out, one clock tick for each step. The program counter, the instruction register, and the control unit that decides what moves where.
Step 1 of 5 · One loop
Step 1 of 5
One loop
A processor runs a program by going round one loop of three steps, over and over, one step on each tick of its clock:
- Fetch. The program counter sends the address it holds out on the address bus. The memory answers on the data bus with the byte at that address, and the byte lands in the instruction register. On the same tick the counter goes up by one.
- Decode. The control unit reads the opcode from the instruction register and raises the control lines the instruction needs, such as MEM read and A in.
- Execute. The lines that are on open one path: one value goes out on a bus, and one block latches it.
Step Clock tick from 0 to 1 to 2, and follow the first instruction, LDA 14: it arrives in the instruction register, the control unit shows its name, and then the number from cell 14 goes into A.
Step 2 of 5
The program counter
The program counter is a small four-bit register, and its whole job is to remember where to fetch the next instruction from. After reset it holds 0, so the first instruction is the one at address 0.
Now tick 2 has finished: LDA 14 has been carried out, and A holds 28. On the next tick the processor will fetch the instruction at address 1.
Step 3 of 5
Three ticks an instruction
Every instruction on this chip takes exactly three ticks, so each step is easy to find: the instruction at address 0 runs on ticks 0, 1 and 2, the one at address 1 on ticks 3 to 5, and so on. On every tick the control unit shows the step, fetch, decode or execute, and the name of the instruction.
Step 4 of 5
Counting ticks
The clock counts from 0. When it stands at tick 5, six ticks have already run: 0, 1, 2, 3, 4 and 5. Step Clock tick on until cell 13 receives the sum, and count.
Step 5 of 5
How many instructions so far
The lid is closed again, and Clock tick stands at 9. Without seeing the blocks, work out how many instructions have run to the end.
Loading the interactive version…
Loading the interactive version…
Each step sets up the Scene for you, and a control marked “fixed” stays put for that step.
Practice · Choose
What happens on a decode tick?
Practice · Choose
What happens on a decode tick?
Practice · Predict, then look
Tick 2 carried out LDA 14, which came from address 0. At tick 3 the processor fetches the instruction at address 1. What will the program counter hold at the end of tick 3?
Practice · Predict, then look
Tick 2 carried out LDA 14, which came from address 0. At tick 3 the processor fetches the instruction at address 1. What will the program counter hold at the end of tick 3?
Practice · Reach the target
Move Clock tick to the tick on which the control unit decodes ADD, the instruction at address 2, and press Check.
Practice · Reach the target
Move Clock tick to the tick on which the control unit decodes ADD, the instruction at address 2, and press Check.
Practice · Calculate
The processor starts from reset at tick 0. The fourth instruction, STA 13, writes the sum to cell 13. How many clock ticks run, from the first up to the one on which the sum is written, both included?
Practice · Calculate
The processor starts from reset at tick 0. The fourth instruction, STA 13, writes the sum to cell 13. How many clock ticks run, from the first up to the one on which the sum is written, both included?
Practice · Calculate
Clock tick stands at 9, and the lid is closed. How many instructions have finished completely, their execute included, by the end of this tick?
Practice · Calculate
Clock tick stands at 9, and the lid is closed. How many instructions have finished completely, their execute included, by the end of this tick?
Lesson complete. Every practice question here is done.