Module 6 · Fetch, Decode, Do It Again

How does a processor work through a program, one instruction at a time?

Lesson 6.2 · Fetch, Decode, Execute

Jenny · Sarah · Mark

Step. Step. Step.

Jenny opens a pretend computer with a few memory boxes, a working number and an arrow pointing at the next instruction.

She says to press Step and watch. Every press does one of three things, in the same order, forever.

Sarah presses it a few times and sees the whole trick. Mark pretends he already knew.

The short answer

One at a time in a loop: fetch, decode, execute, next. Grandma Ruth’s grocery bills took five instructions and fifteen steps. Her laptop does about two billion steps a second, so when the graph says 12%, it’s waiting most of the time, not struggling.

Try it yourself

Press Step and watch the processor fetch, decode and execute each instruction. It’s adding Grandma Ruth’s two grocery bills.

Next instruction at0
Working number0

Memory

0LOAD 5
1ADD 6
2STORE 7
3OUT
4HALT
534first bill
619second bill
70total

Screen

0 steps so far

See it in 3DHow a processor runs one instruction

What you just did has a name

The fetch-decode-execute cycle

The fetch-decode-execute cycle is the loop every processor runs.

Fetch: grab the next instruction from memory. Decode: work out what it means and which parts of the chip need to do something.

Execute: do it, whether that’s math in the ALU, copying a number or jumping somewhere else.

Then go to the next instruction and do it again, billions of times a second, until the computer turns off.

A few more things

The control unit runs the loop

One part of the processor, the control unit, fetches and decodes, then signals the ALU, the memory and everything else to do their parts. It’s the manager from Module 5’s kitchen.

The program counter

The processor keeps one special number that says where the next instruction is. It goes up by one after each instruction, unless a jump changes it. Lesson 6.4 plays with that.

Modern chips overlap

Real processors work on several instructions at once, fetching one while decoding the next and executing a third, like an assembly line. The steps are the same. They just overlap.

Go deeper

The longer version, if you want it.

Pipelines and guesses

To go faster, modern processors split the cycle into many small stages and keep every stage busy with a different instruction. It’s called pipelining. When there’s a jump coming, the processor often guesses which way it will go and starts on that path early.

If it guessed right, time saved. If it guessed wrong, it throws away the work and starts over. Modern chips guess right most of the time, which is a big part of why they’re fast.

Quick check

In which step does the processor work out what an instruction means?

Let’s take it slower

Think back to Module 5’s kitchen. The manager picks up the next recipe card: fetch. Reads it and works out what it wants: decode. Hands it to the cook, who chops the onion: execute. Then the next card. The manager is the control unit, and it does that a few billion times a second without getting bored.

More examples

1

One swipe through a feed

A single swipe on your phone is millions of trips around the loop. The processor reads where your finger is, works out how far the page should move, decides what comes into view and tells the screen, about sixty times a second.

2

A laptop just sitting there

Leave a laptop alone on the desktop and the processor still isn’t stopped. It naps in low power, and a keypress, a timer or a Wi-Fi signal taps it awake.

Back to the question

So how does a processor work through a program?

Show the answer

One at a time in a loop: fetch, decode, execute, next. Grandma Ruth’s grocery bills took five instructions and fifteen steps. Her laptop does about two billion steps a second, so when the graph says 12%, it’s waiting most of the time, not struggling.

More on this: CPU vs. GPU: what’s the difference?

One last question

Rob asks what a processor actually does. Who explained it best?

Talk Card

Talk Card · 6.2

When a computer looks busy, it’s grabbing an instruction, working out what it means and doing it, billions of times a second.

How Computers Work · pettigrewlab.com/learn

Next lesson