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.
It's like
The interactive parts didn't load. The explanations below still work; try reloading the page.
One instruction's journey
- When you press a key, the keyboard sends a signal down the wire. Keyboards, mice and microphones are input devices: they send information in.
- 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.
- Step one is fetch. The processor checks its step counter, asks memory for that instruction, and the instruction travels back along the wires.
- Step two is decode. The instruction is really just a number. The processor's control unit works out what the number means: add three!
- 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.
- 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!
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.
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?
- Set the clock to slow and press Run. Watch fetch, decode and execute light up.
- Press Reset, set the clock to fast and run it again.
- 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.
Program the computer
Build a program that makes the screen show the target number. Don't forget a SHOW instruction!
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
-
Which part follows the program's instructions?
Show the answer
The processor. The processor fetches, decodes and executes each instruction.
-
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.
-
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.
-
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.
-
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.
-
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.
You're a Computers & communication expert!
You watched, looked inside, tried it, solved the challenge and went deeper. Pick another question below, or switch the age at the top to see this topic another way.
Keep exploring
Games to play next
- Robot RoutesSnap together arrow, repeat and dance blocks to guide Bolt the robot home.
- Bug DetectiveA robot program almost works. Run it, spot the buggy block, and fix it.
- Safe Message DetectiveRead made-up messages, pop-ups and posts, spot the clues, and choose the safe, kind thing to do.
Guide for grown-ups
- How to start homeschooling: a step-by-step guide for familiesA guide for parents · 7 min read
Coding games by grade
Computer skills worksheets by grade
- Preschool Computer Skills Worksheets
- Pre-K Computer Skills Worksheets
- Kindergarten Computer Skills Worksheets
- 1st Grade Computer Skills Worksheets
- 2nd Grade Computer Skills Worksheets
- 3rd Grade Computer Skills Worksheets
- 4th Grade Computer Skills Worksheets
- 5th Grade Computer Skills Worksheets
- 6th Grade Computer Skills Worksheets
- 7th Grade Computer Skills Worksheets
- 8th Grade Computer Skills Worksheets