← Back to course
4/6
Week 03 Β· The processor

Thursday

Inside one step
// One instruction at a time, billions of times a second
⏱ about 15 min

Thursday: Inside one step

Rocket wants to know everything. "So the processor reads a step, the clock ticks and switches flip. But how does it all fit?"

Raven draws a box on the whiteboard with an arrow going in and out. "What do you notice?" she asks. "A step goes in. An answer comes out."

Nova lights up a path through the box. "Let me show you one tick," she says. "Would you like a hint? Fetch, do, next. Every single time."

Fetch, do, next

Every instruction follows the same three moves inside the processor.

Fetch: the processor gets the next instruction from memory. Do: it carries out that one step. Next: it points at the following instruction.

Then the clock ticks and the three moves happen again. Fetch, do, next, tick. Fetch, do, next, tick.

The instructions and the numbers are all in binary. The processor is a huge pattern of switches that flips in time with the clock.

Fetch the next instruction from memory
Do that one step
Point at the next instruction
Clock ticks, repeat

Trace a tiny program

You can act out a processor on paper. Start with a number. Follow each instruction in order. Never skip one.

Here is a tiny program. Trace it one step at a time.

StepInstructionNumber after the step
1Start with 22
2Add 35
3Double it10
4Take away 46

The processor does not know the answer early. It only knows the number after each step. That is exactly how it works inside a real machine.

Trace this: start with 4, add 2, double it. What number comes out?
WHY THIS EXERCISE4 + 2 = 6, then 6 doubled is 12. One step at a time gets the right answer.
Start with 5. Add 5. What is the number now?
Then take away 3. What is the number now?
Then double it. What is the number now?
PUT THE THREE MOVES OF ONE TICK IN ORDER
  • ?The clock ticks
  • ?Fetch the next instruction
  • ?Point at the next instruction
  • ?Do that one step
WHY THIS EXERCISEFetch, do, next, tick is the heartbeat of every processor ever built.
INSIDE THE PROCESSOR
  • Read the question.
  • Tap your answer.
Where does the processor fetch the next instruction from?
What are the instructions and numbers made of inside the processor?
Trace this: start with 10, take away 4, double it. What comes out?
StatementTrue or false?
The processor fetches instructions from memory.?
The processor can do a step before it fetches it.?
Order does not matter when tracing a program.?
Inside the processor, numbers are stored as bits.?
WHY THIS EXERCISEThe processor is strict about order. That strictness is what makes its answers reliable.

One more idea. Many processors today have several cores. A core is a complete fetch, do, next machine.

A processor with four cores can follow four lists at once, one per core. It is like four cooks in one kitchen, each with a recipe.

Even so, each core still does one instruction at a time.

Try it
Write a four step program on paper: start, add, double, take away.
Give it to a partner. They trace it one step at a time.
Check their answer by tracing it yourself.

You traced a program like a real processor! Tomorrow you will review the week and run the Fix-It Bay for a day.

← Wednesday