Skip to content
PlayOwl
Computers & communication · #54

How does a computer follow instructions?

A computer follows a list of tiny instructions, one after another, millions of times a second.

The big idea: A computer's processor gets an instruction from memory, works out what it means, and does it. Then it gets the next one. A program is just a list of these tiny steps.

Start exploring
0 of 5 parts done
A friendly computer with a glowing processor chip and instruction cards flying along circuit paths, How Things Work poster
1Watch it

One instruction's journey

  1. When you press a key, the keyboard sends a signal down the wire. Keyboards, mice and microphones are input devices: they send information in.
  2. Programs are kept in storage, which remembers them even when the power is off. To run a program, the computer copies it into memory, which is much faster.
  3. Step one is fetch. The processor checks its step counter, asks memory for that instruction, and the instruction travels back along the wires.
  4. Step two is decode. The instruction is really just a number. The processor's control unit works out what the number means: add three!
  5. Step three is execute. The math part of the processor adds the numbers, and the answer goes into a register, a tiny memory box inside the processor.
  6. An output instruction sends the answer to the screen. Then the processor fetches the next instruction. It repeats these three steps millions of times every second!
2Look inside

Open up a computer

Tap each part of the computer. Watch what it does when you find it!

  • Processor (CPU). The processor follows the program's instructions. It fetches each one, works out what it means and does it, millions of times a second.
  • Memory (RAM). Memory holds the program that is running and the numbers it is using. It is fast, but it forgets everything when you turn the computer off.
  • Storage drive. The storage drive keeps programs, photos and games even when the power is off. It holds much more than memory, but it is slower.
  • Input devices. Input devices send information into the computer. Each key press or mouse click becomes a signal that the processor can read.
  • Output devices. Output devices bring information out of the computer. The screen shows pictures and words, and speakers play sounds.
  • Wires (the bus). Thin metal paths on the board carry signals between the processor, memory and other parts. They are called a bus.
  • Clock. The clock sends out regular pulses, like a drumbeat. Each beat tells the processor when to do its next tiny step.
  • Fan and heat sink. All that switching makes the processor warm. Metal fins soak up the heat and a fan blows it away.
  • Power supply. The power supply takes electricity from the wall socket and changes it into the gentle, steady electricity the parts need.
3Try it

Follow the instructions, step by step

Press One step to watch one stage at a time, One instruction for a whole cycle, or Run to let the clock drive it. Then change the clock speed and run the program again.

Experiment: What happens when you make the clock tick faster?

  1. Set the clock to slow and press Run. Watch fetch, decode and execute light up.
  2. Press Reset, set the clock to fast and run it again.
  3. Compare the answer on the screen and how long it took.

What we found: A faster clock does not change what the processor does. It still fetches, decodes and executes every instruction in the same order, and gets the same answer. It just finishes sooner.

Turn on JavaScript to try it yourself.

4Solve a challenge

Program the computer

Build a program that makes the screen show the target number. Don't forget a SHOW instruction!

5Go deeper

How a computer follows a program

A computer is not clever on its own. It can only do very simple jobs, like adding two numbers, comparing them or moving a number from one place to another. What makes it powerful is that it does these tiny jobs incredibly fast and never gets bored.

A program is a list of these tiny jobs, called instructions. The processor works through the list in three steps: fetch the next instruction from memory, decode it to work out what it means, and execute it. Then it moves to the next one.

Memory and storage are different. Storage keeps your games and photos even when the computer is off. Memory is much faster, so programs are copied into it while they run, but it forgets everything when the power goes off.

Every game, video and drawing app is built from millions of tiny instructions like these. Programmers write programs in languages that people can read, and special programs translate them into the simple instructions a processor understands.

Key words

Processor (CPU)
The part of a computer that follows instructions.
Memory (RAM)
Fast storage for the program that is running. It forgets when the power is off.
Instruction
One tiny job for the processor, such as add, load or show.
Register
A tiny memory box inside the processor that holds the number it is working on.
Program counter
A register that holds the address of the next instruction to fetch.
Clock speed
How many steps the processor can do each second.

Check your thinking

  1. Which part follows the program's instructions?

    Show the answer

    The processor. The processor fetches, decodes and executes each instruction.

  2. Which of these is an output device?

    Show the answer

    The screen. The screen shows information coming out. The keyboard and mouse put information in.

  3. What are the three steps the processor repeats?

    Show the answer

    Fetch, decode, execute. First it gets the instruction, then works out what it means, then does it.

  4. Why is a program copied from storage into memory to run?

    Show the answer

    Memory is much faster for the processor to reach. Memory is fast, so the processor doesn't have to wait. Storage is big and keeps things safe when the power is off.

  5. In our 8-bit model the opcode for ADD is 0010. What does 0010 0101 mean?

    Show the answer

    ADD 5. The first four bits (0010) are the opcode ADD; the last four (0101) are the operand, 5 in binary.

  6. If the clock ticks twice as fast, what happens to a program?

    Show the answer

    Same answer, finished sooner. The processor does exactly the same steps, just faster.