edubun
English
1 / 19

5 / 6 · Intro

What a CPU does

A 3 GHz processor ticks 3 billion times a second, one tick every third of a nanosecond.

Jump to the 10 practice questions

You will learn

  • Follow fetch, decode and execute step by step
  • Work out how long a clock tick is

Before this: How gates add numbers

1Explain

Three students play the CPU

Picture a computer class. (This is a made-up scene.) Sixteen numbered boxes are drawn on the board, each with eight bits written in it. Three students play the CPU. One holds a card marked PC, one a card marked IR, one a card marked ACC. The PC card says 0. The IR student walks to box 0 and copies what is there, 0001 1110, and the PC student changes the card to 1. The class looks up the first four bits in a table on the wall: 0001 means LOAD. The last four, 1110, are 14.

2Explain

Twelve moves

Box 1 says ADD 15, so ACC becomes 7 + 5 = 12. Box 2 says STORE 13, and the ACC student writes 12 into box 13. Box 3 says HALT, and everyone sits down. Twelve moves in all. None of the three needed to know that the program "adds 7 and 5". Each one followed one small rule. The boxes are the memory, the cards are registers and the table on the wall is the decoder. A real CPU works the same way, billions of times a second, and nobody inside it understands the program either.

3Explore

The same short loop, billions of times a second

Gates can add, compare and choose, but something has to tell them what to do, in what order and with which numbers. That is the job of the central processing unit, the CPU. It repeats one short loop. The program counter (PC) holds the address of the next instruction. Fetch: the CPU reads the cell the PC points to into the instruction register (IR) and moves the PC on by one. Decode: control circuits look at the opcode bits and set up the right paths, for instance connecting the adder for ADD.

Loading

Drag to turn. Scroll or pinch to zoom.

The program in cells 0 to 3 adds 7 (cell 14) and 5 (cell 15) and stores 12 in cell 13. Press Step to move one phase at a time and watch PC, IR and ACC. Four instructions take twelve phases. Then pick 4 × 3, which multiplies by adding 4 three times with a loop, or Count down.

4Problem

The three phases

Put the phases of the instruction cycle in order.

  1. Execute
  2. Fetch
  3. Decode
Hint

Read it, work out what it means, do it.

Solution

Answer:

  1. Fetch
  2. Decode
  3. Execute

Read the instruction, work out what it means, then do it.

5Problem

The PC after a fetch

The CPU fetches the instruction at address 3. What is the PC right after the fetch?

Hint

The PC moves on by one during the fetch.

Solution

Answer: 4

Fetch moves the PC on by one to the next instruction.

6Explain

Phases of the 7 + 5 program

The scene runs the same program the class acted out. Press Step and the PC, IR and ACC change exactly as the cards did: LOAD 14, then ADD 15, STORE 13 and HALT, four instructions of three phases each, twelve phases in all. The multiplication program uses the same few instructions. Its JZ and JUMP send the PC back to 0 twice before the counter in cell 15 reaches zero. So it runs 24 instructions in 72 phases. Six times the instructions of the addition.

7Problem

Instructions run

How many instructions does the 7 + 5 program run, including HALT?

Hint

LOAD, ADD, STORE, HALT.

Solution

Answer: 4

LOAD 14, ADD 15, STORE 13, HALT.

8Problem

Phases in all

Each instruction takes three phases. How many phases does the 7 + 5 program take?

Hint

4 instructions × 3 phases.

Solution

Answer: 12

4 instructions × 3 phases = 12.

9Explain

The program sits in the same memory as the numbers

On the board, the instructions and the numbers 7 and 5 were in the same row of boxes. That is no accident. In June 1945 John von Neumann wrote the "First Draft of a Report on the EDVAC". It described a computer that keeps its instructions in the same memory as its data. Almost every computer since has worked that way. An instruction is just a number whose bits are split into fields.

OpcodeNameWhat it does
0000HALTStop
0001LOAD aACC = cell a
0010ADD aACC = ACC + cell a
0011SUB aACC = ACC − cell a
0100STORE acell a = ACC
0101JUMP aPC = a
0110JZ aif ACC = 0, PC = a

10Problem

Decode 0010 1111

In the toy computer, what does 0010 1111 mean?

Hint

0010 is ADD and 1111 is 15.

Solution

Answer: ADD 15

Opcode 0010 is ADD; address 1111 is 15.

11Problem

Encode LOAD 14

Write LOAD 14 as 8 bits.

Hint

LOAD is 0001 and 14 is 1110.

Solution

Answer: 00011110

LOAD is 0001 and 14 is 1110.

12Problem

STORE 13

What does STORE 13 do?

Hint

STORE writes the accumulator into memory.

Solution

Answer: Copies the accumulator into cell 13

STORE writes from the CPU to memory; LOAD reads the other way.

13Problem

Repeating a loop

Which instruction lets a program repeat a loop until a count reaches zero?

Hint

It jumps only when the accumulator is 0.

Solution

Answer: JZ (jump if zero)

A conditional jump chooses between going round again and leaving the loop.

14Problem

The First Draft

In which year did von Neumann write the First Draft of a Report on the EDVAC?

Hint

June of the last year of the Second World War.

Solution

Answer: 1945

It is dated 30 June 1945.

15Explain

How fast the loop goes

The steps keep time with a clock signal, a voltage that flips on and off at a steady rate. A 3 GHz clock ticks 3,000,000,000 times a second, so one tick lasts 1 ÷ 3,000,000,000 seconds, about 0.333 nanoseconds. Light covers only about 10 centimetres in that time. At one phase per tick, that is enough ticks to run the toy's 7 + 5 program 250 million times a second. Real processors don't finish one whole instruction per tick in the simple way our toy does.

16Problem

One tick at 3 GHz

A clock runs at 3 GHz. How long is one tick, in nanoseconds? (three decimal places)

ns

Hint

1 ÷ 3 nanoseconds.

Solution

Answer: 0.333 ns

One tick lasts 1 ÷ 3,000,000,000 s ≈ 0.333 × 10⁻⁹ s = 0.333 ns. Taking the reciprocal gives seconds per tick, which must then be converted to nanoseconds.

17Practice

The toy CPU in JavaScript

The loop already fetches, decodes, runs LOAD and stops at HALT. Add the two missing rules: ADD a (ACC = ACC + cell a) and STORE a (cell a = ACC). Then cell 13 holds 12 and four instructions have run.

Expected output
12
4
Your code
const mem = [0x1E, 0x2F, 0x4D, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 5];
let pc = 0, acc = 0, count = 0;
while (true) {
  const ir = mem[pc];
  pc = pc + 1;
  const op = ir >> 4, a = ir & 15;
  count++;
  if (op === 0) break;
  if (op === 1) acc = mem[a];
}
console.log(mem[13]);
console.log(count);
Hint

ADD is opcode 2 and STORE is opcode 4, as in the table.

A solution
const mem = [0x1E, 0x2F, 0x4D, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 5];
let pc = 0, acc = 0, count = 0;
while (true) {
  const ir = mem[pc];
  pc = pc + 1;
  const op = ir >> 4, a = ir & 15;
  count++;
  if (op === 0) break;
  if (op === 1) acc = mem[a];
  if (op === 2) acc = acc + mem[a];
  if (op === 4) mem[a] = acc;
}
console.log(mem[13]);
console.log(count);

18Explain

Common mistakes

  • "The PC counts how many instructions have run."

    The PC holds the address of the next instruction. In the 4 × 3 program it is sent back to 0 twice, while the number of finished instructions keeps climbing to 24.

  • "The CPU reads a program the way we read it."

    It reads 8 bits, splits them into an opcode and an address, and follows fixed wiring for that opcode. Like the students with the cards, it never knows that the program adds 7 and 5.

  • "A higher GHz number always means a faster computer."

    The clock sets how often a step can happen, not how much gets done in each tick. Real chips overlap instruction phases and have several cores, so two chips at the same GHz can finish very different amounts of work.

19

Summary

  • Programs are stored as numbers in the same memory as data (von Neumann, 1945).
  • The CPU repeats fetch, decode, execute; the PC points to the next instruction.
  • An instruction's bits split into an opcode and an address.
  • The clock sets the pace: 3 GHz is one tick every 0.333 ns.

Next unitMemory and storage
Full text · The whole lesson as one text

Picture a computer class. (This is a made-up scene.) Sixteen numbered boxes are drawn on the board, each with eight bits written in it. Three students play the CPU. One holds a card marked PC, one a card marked IR, one a card marked ACC. The PC card says 0. The IR student walks to box 0 and copies what is there, 0001 1110, and the PC student changes the card to 1. The class looks up the first four bits in a table on the wall: 0001 means LOAD. The last four, 1110, are 14. So the ACC student goes to box 14 and copies the 7 she finds there. Then the whole thing starts again from box 1.

Box 1 says ADD 15, so ACC becomes 7 + 5 = 12. Box 2 says STORE 13, and the ACC student writes 12 into box 13. Box 3 says HALT, and everyone sits down. Twelve moves in all. None of the three needed to know that the program "adds 7 and 5". Each one followed one small rule. The boxes are the memory, the cards are registers and the table on the wall is the decoder. A real CPU works the same way, billions of times a second, and nobody inside it understands the program either.

The same short loop, billions of times a second

Gates can add, compare and choose, but something has to tell them what to do, in what order and with which numbers. That is the job of the central processing unit, the CPU. It repeats one short loop. The program counter (PC) holds the address of the next instruction. Fetch: the CPU reads the cell the PC points to into the instruction register (IR) and moves the PC on by one. Decode: control circuits look at the opcode bits and set up the right paths, for instance connecting the adder for ADD. Execute: the work is done. A number is loaded, added or stored, or the PC is changed so the program jumps somewhere else. Then the loop starts over. One instruction, JZ, jumps only when the accumulator is zero, and that single kind of jump is what lets a program decide and repeat.

The program in cells 0 to 3 adds 7 (cell 14) and 5 (cell 15) and stores 12 in cell 13. Press Step to move one phase at a time and watch PC, IR and ACC. Four instructions take twelve phases. Then pick 4 × 3, which multiplies by adding 4 three times with a loop, or Count down.

The scene runs the same program the class acted out. Press Step and the PC, IR and ACC change exactly as the cards did: LOAD 14, then ADD 15, STORE 13 and HALT, four instructions of three phases each, twelve phases in all. The multiplication program uses the same few instructions. Its JZ and JUMP send the PC back to 0 twice before the counter in cell 15 reaches zero. So it runs 24 instructions in 72 phases. Six times the instructions of the addition.

The program sits in the same memory as the numbers

On the board, the instructions and the numbers 7 and 5 were in the same row of boxes. That is no accident. In June 1945 John von Neumann wrote the "First Draft of a Report on the EDVAC". It described a computer that keeps its instructions in the same memory as its data. Almost every computer since has worked that way. An instruction is just a number whose bits are split into fields. In this toy computer each cell holds 8 bits. The first four say what to do, the opcode, and the last four say which cell to use, the address. 0001 is LOAD, so 0001 1110 means "LOAD 14": copy the number in cell 14 into the accumulator, the CPU's working register.

How fast the loop goes

The steps keep time with a clock signal, a voltage that flips on and off at a steady rate. A 3 GHz clock ticks 3,000,000,000 times a second, so one tick lasts 1 ÷ 3,000,000,000 seconds, about 0.333 nanoseconds. Light covers only about 10 centimetres in that time. At one phase per tick, that is enough ticks to run the toy's 7 + 5 program 250 million times a second. Real processors don't finish one whole instruction per tick in the simple way our toy does. They overlap the phases of several instructions like an assembly line, which is called pipelining, and today's chips hold several complete processors, called cores, side by side. The toy has none of that, which is exactly why you can follow it by hand.

OpcodeNameWhat it does
0000HALTStop
0001LOAD aACC = cell a
0010ADD aACC = ACC + cell a
0011SUB aACC = ACC − cell a
0100STORE acell a = ACC
0101JUMP aPC = a
0110JZ aif ACC = 0, PC = a
Common mistakes
  • "The PC counts how many instructions have run." The PC holds the address of the next instruction. In the 4 × 3 program it is sent back to 0 twice, while the number of finished instructions keeps climbing to 24.
  • "The CPU reads a program the way we read it." It reads 8 bits, splits them into an opcode and an address, and follows fixed wiring for that opcode. Like the students with the cards, it never knows that the program adds 7 and 5.
  • "A higher GHz number always means a faster computer." The clock sets how often a step can happen, not how much gets done in each tick. Real chips overlap instruction phases and have several cores, so two chips at the same GHz can finish very different amounts of work.
Teacher's noteAct it out before showing the scene. Draw sixteen boxes, hand out three cards (PC, IR, ACC) and run the 7 + 5 program one phase at a time, with the class calling out each phase. The point where learners get lost is that the PC moves on during fetch, so by the time an instruction executes, the PC already points at the next one. Stop after the first fetch and ask what the PC says. JUMP and JZ then make sense as "write a new number on the PC card". Once the play-acting works, the scene's Step button feels familiar.
Key points
  • Programs are stored as numbers in the same memory as data (von Neumann, 1945).
  • The CPU repeats fetch, decode, execute; the PC points to the next instruction.
  • An instruction's bits split into an opcode and an address.
  • The clock sets the pace: 3 GHz is one tick every 0.333 ns.

Practice questions from What a CPU does on edubun

Embed this quiz

Free to embed. Please keep the credit line.

Sources for this course (10)
  • (checked 2026-10-17)
  • Standards: NIST, "Prefixes for binary multiples" (physics.nist.gov/cuu/Units/binary.html: IEC approved kibi, mebi, gibi in December 1998; 1 B = 8 bit; 1 MiB = 1 048 576 B; 1 MB = 1 000 000 B; 1 GiB = 1 073 741 824 B; historical note: memory makers usually mean 2²⁰ bytes by megabyte, storage makers 1 000 000, and the "1.44 MB" diskette uses a megabyte of 1 024 000 bytes)
  • IETF RFC 20 "ASCII format for Network Interchange" (1969, 7-bit codes, A = 65, a = 97, 0 = 48)
  • IETF RFC 3629 "UTF-8, a transformation format of ISO 10646" (2003: 1 to 4 octets per character, ASCII unchanged, code points up to U+10FFFF, U+0800 to U+FFFF take three octets, "the first octet of a multi-octet sequence indicates the number of octets", example U+D55C U+AD6D U+C5B4 = ED 95 9C EA B5 AD EC 96 B4)
  • Official documentation: MDN Web Docs, "<color>" (hexadecimal colour notation #RRGGBB)
  • Intel, "Intel Chips" timeline poster (2012: Intel 4004 of 1971 with 2,300 transistors; 2nd generation Core 2010 with 1.16 billion)
  • Teaching model: the toy computer in the network-lab scene (16 cells of 8 bits, 4-bit opcode and 4-bit address) is made for this course, not a real chip. History blocks only (the logic-gates story and the von Neumann paragraph of the-cpu): George Boole, An Investigation of the Laws of Thought (1854, Project Gutenberg 15114)
  • Claude E. Shannon, "A Symbolic Analysis of Relay and Switching Circuits", Transactions of the AIEE vol. 57 (1938)
  • abstract of his MIT master's thesis. Computer History Museum, The Silicon Engine, "1947: Invention of the Point-Contact Transistor" (Bardeen and Brattain, December 1947, germanium)
  • John von Neumann, "First Draft of a Report on the EDVAC" (30 June 1945, Moore School, reprinted in IEEE Annals of the History of Computing 15:4, 1993).

Checked: 2026-10-17