A processor repeats one cycle: fetch the instruction the program counter points at, decode it, execute it, one step per clock tick. The program is numbers in the same memory as the data. Step a tiny processor, change its program, and write your own.
Your games, apps and websites all end up as simple instructions like ADD and JUMP. What does a processor actually do with them?
A processor is gates, registers and memory working together. It does one tiny thing per clock tick, again and again: fetch an instruction, decode it, execute it.
Predict: Read the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
Try: Try it on the board and compare the result with your prediction.
Investigate: Work out why it happens, one step at a time.
Modify: Change the problem on purpose and see what happens.
Practise: A few on your own, to check you have it.
Make: Make your own problem using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
What will it output?
TryTry it on the board and compare the result with your prediction.
Try: tick by tick
Was your prediction right?
Try it yourselfYour edits are saved in this browser.
Press Clock tick (or Whole instruction) until it halts. Watch the PC, the instruction register and the accumulator.
Use the board. This ticks when you get there.
InvestigateWork out why it happens, one step at a time.
Worked example: one instruction, three ticks
Worked exampleBefore each step, say what you think comes next.
fetch: IR=cell 0=22,PC=1LOAD 6 is stored as 1 × 16 + 6 = 22. The PC moves on, ready for next time.
decode: 22=1×16+6Operation 1 is LOAD; the address is 6.
execute: ACC=cell 6=5Copy the number in cell 6 into the accumulator.
next: fetch cell 1The PC says where to go next: ADD 7.
Now count the ticks for the whole program.
Each instruction takes three clock ticks. How many ticks does the whole program (LOAD, ADD, OUT, HALT) take?
Sam explains the memory. Click the line where it first goes wrong.
ModifyChange the problem on purpose and see what happens.
Vary: change the program
Try it yourselfYour edits are saved in this browser.
Change one data cell so the program outputs 12. Type in the cell, then run it.
Use the board. This ticks when you get there.
Change one instruction so the program outputs 5 − 3.
Use the board. This ticks when you get there.
This program stores its answer. Run it: what ends up in cell 9?
Use the board. This ticks when you get there.
This program counts down from 3 using JUMP and JZ. Make it count down from 5.
Use the board. This ticks when you get there.
PractiseA few on your own, to check you have it.
The cycle
MakeMake your own problem using what you have learned. Expect a few tries; that is normal.
Write a program
Then: can you do it with a loop instead, so it would work for 2, 4, 6, 8, 10 without more cells?
Try it yourselfYour edits are saved in this browser.
Need a hint?
Cell 15 holds 2. Every output needs an OUT just before it.
Memory is empty except cell 15, which holds 2. Write a program that outputs 2, 4, 6 and then halts.
Use the board. This ticks when you get there.
For teachers
Students step a tiny processor through fetch, decode and execute one clock tick at a time, change its program and data, follow a loop, and write a program of their own (AC9TDI8K04 node 3, extended; links to AC9TDI8K01). About 50 minutes.
I can describe the fetch, decode and execute cycle.
I can say what the program counter and accumulator hold.
I can explain that instructions are numbers stored in memory.
I can write a short program for a tiny processor.
Before class
Try the boards yourself. The instruction set is deliberately tiny: HALT, LOAD, ADD, SUB, STORE, JUMP, JZ (jump if zero) and OUT. Each instruction is a number: operation × 16 + address, so LOAD 6 is 22. Numbers wrap at 256.
The one idea: a processor repeats one cycle: fetch the instruction the program counter points at, decode it, execute it, one step per clock tick. The program is numbers in the same memory as the data (the stored-program idea).
Simplifications: one register (the accumulator), 16 cells, three ticks per instruction. Real processors overlap the steps (pipelining) and have many registers. It is similar in spirit to the Little Man Computer, which some teachers will know.
Running the lesson
Predict: students who said 53 are joining digits, not adding.
Try: ask what PC shows just after a fetch, and why it is already one ahead.
Worked example: model the three ticks for LOAD 6 aloud.
Vary: in the loop, ask which instruction makes it repeat and which one stops it.
Make: collect programs: who used the fewest cells?
The hard part (on purpose)
Writing the Make program from an empty memory is the hard part. Have students write the outputs they want first, then the instruction before each OUT.
When students get stuck
A student thinks code and data are kept apart (Sam's mistake). Ask: What number is LOAD 6? Where is it stored? Fix: Instructions are numbers in the same memory as the data.
A student's program runs off the end. Ask: What should happen after the last OUT? Fix: End with HALT.
Stretch and support
Stretch: Write a program that multiplies 3 by 4 using a loop of ADDs. How many clock ticks does it take?
Support: An instruction card: each instruction, what it does, and an example.
Where it leads
Links: Inside a computer: 3 GHz means about 3 billion clock ticks a second, and each core is a processor like this (much bigger). Code pathway: the Python and MakeCode programs students write are turned into instructions like these.
What each step is for
what will it output?: Committing to the program's output tests the new move: the processor works through the cells one instruction at a time.
Try: tick by tick: Ticking through the program settles the prediction and shows the new move: each instruction is fetched, decoded and executed in turn.
Worked example: one instruction, three ticks: Tracing LOAD 6 through fetch, decode and execute models the new move. Sam keeps instructions and numbers apart, the misconception planted after the method.
Vary: change the program: Each task changes one thing: a data cell, then one instruction, then STORE instead of OUT, then the start of a loop.
the cycle: Reasoning about the cycle without the board is the same move in mixed forms, plus a review of adders.
write a program: Writing a program from an empty memory reverses the process: from the outputs wanted to the instructions that make them.
Now you can
Describe the fetch, decode and execute cycle.
Say what the program counter and accumulator hold.
Explain that instructions are numbers stored in memory.