What a Computer Is Made Of
A system on chip is a whole computer on one piece of silicon. Before you open the chip, build the computer: three parts and one loop.
You Will Be Able To
- Name the three parts of a computer and the job of each.
- Explain how a program is stored as numbers, and how the processor steps through it.
- Run a four-instruction program by hand: fetch, decode and execute, one round at a time.
- Lesson
- S0.1
- Time
- 25 min
- Runs on
- Your browser
- Check
- 5 questions
A phone, a washing machine and a car key each contain a system on chip, or SoC. An SoC is a complete computer built on one piece of silicon. Every lesson in this track opens one part of that chip. First, though: what is a computer, and what does it do all day?
Before You Start
You need binary numbers and the idea that a flip-flop stores one bit. You do not need to know anything about processors, programming or chips.
The answer to the opening question is short: a computer has three parts, and it repeats one loop. This page builds both from nothing, with numbers small enough to check by hand.
| Question | |
|---|---|
| 1 | What are the three parts of a computer, and what does each one do? |
| 2 | What is an address, and how does it differ from the number stored there? |
| 3 | A program is "stored as numbers". What does that mean? |
| 4 | What does the program counter hold, and when does it change? |
| 5 | Why can a processor not tell an instruction from data? |
The Idea: Three Parts and One Loop
A computer is a machine that follows a list of very small orders, one at a time. It has three parts.
| Part | What it is | Its job |
|---|---|---|
| Memory | A long row of numbered boxes. Each box holds one number. | Keeps the list of orders, and the numbers they work on. |
| Processor | A circuit that reads one order, carries it out and moves to the next. | Does the work. |
| Input and output (I/O) | Circuits that touch the outside world: a switch, a lamp, a keyboard. | Lets facts in and results out. |
Each order is called an instruction. The whole list is the program. The surprise is where the program lives. It sits in the same memory as the data, written as plain numbers.
So the processor does one thing all day. It reads the next number from memory, works out what that number asks for, does it, and goes round again. That loop is called fetch, decode, execute.
Why build a machine this way? Because then the wires never have to change. To give the same chip a new job, you change the numbers in memory. That one idea lets a single processor design run a thermostat today and a drone tomorrow.
New Words
| Word | Meaning |
|---|---|
| Memory | A row of boxes. Each box stores one number. On this page a box holds eight bits: a number from 0 to 255. |
| Address | The number of a box. Box 10 has address 10. The address says where. The content says what. |
| Register | A row of flip-flops inside the processor that holds one number. The processor reaches it at once, with no address. |
| Instruction | One small order, such as "copy box 10 into register A". It is stored in a box as a number. |
| Program | A list of instructions in neighbouring boxes. |
| Program counter (PC) | The register that holds the address of the next instruction. |
| Fetch, decode, execute | The three steps of the loop: read the instruction, work out what it asks, do it. |
Keep one pair apart from the start: the address and the content. "Box 10 holds 5" has two numbers in it. 10 is where to look. 5 is what you find.
The Smallest Computer: Four Instructions
Our machine has sixteen memory boxes, with addresses 0 to 15. Its processor has two registers: the PC, and one working register called A. It understands four instructions.
| Instruction | What it does | Kind |
|---|---|---|
| LOAD n | Copy the content of box n into A. | 1 |
| ADD n | Add the content of box n to A. | 2 |
| STORE n | Copy A into box n. | 3 |
| HALT | Stop. | 0 |
An instruction must fit in one box, as one number. This machine uses one rule: kind times 16, plus the address. So LOAD 10 is 1 × 16 + 10, which is 26. In bits, 26 is 0001 1010: the top four bits hold the kind and the bottom four hold the address.
Here is a program that adds two numbers. The program sits in boxes 0 to 3. Its data sits in boxes 10 to 12.
| Box (address) | Content | Meaning |
|---|---|---|
| 0 | 26 | LOAD 10 (1 × 16 + 10) |
| 1 | 43 | ADD 11 (2 × 16 + 11) |
| 2 | 60 | STORE 12 (3 × 16 + 12) |
| 3 | 0 | HALT |
| 10 | 5 | data: the first number |
| 11 | 7 | data: the second number |
| 12 | 0 | data: the answer goes here |
One Picture: One Round of the Loop
- Processor
- Memory
- Peripheral
- Three parts
The left column is the processor. The middle column is memory. The right box is input and output, which the next lesson connects.
- Memory is numbered boxes
Every box holds one number. Boxes 0 to 3 hold the program. Boxes 10 to 12 hold data. The boxes look the same.
- Fetch
The PC holds 0, so the processor reads box 0. The number 26 comes back.
Follow the calls, values and waits
- data 26: Memory, boxes 0 to 3 → Decode and execute
- Decode
The processor splits 26 into kind 1 and address 10, by the rule above. Kind 1 means LOAD.
- Execute
LOAD 10 copies the content of box 10 into register A. A now holds 5.
Follow the calls, values and waits
- data 5: Memory, boxes 10 to 12 → Register A
- Step the PC, and go round again
The PC moves from 0 to 1. The next round fetches box 1. The loop never stops until a HALT.
Read the diagram as text
- Program counter (PC): address of the next instruction
- Decode and execute: works out what the fetched number asks for
- Register A: the one number being worked on
- Memory, boxes 0 to 3: the program: 26, 43, 60, 0
- Memory, boxes 10 to 12: the data: 5, 7, 0
- Input and output: a switch, a lamp, a keyboard
- Program counter (PC) → Memory, boxes 0 to 3: which box?
- Memory, boxes 0 to 3 → Decode and execute: the number in it
- Memory, boxes 10 to 12 → Register A: LOAD, ADD
- Register A → Memory, boxes 10 to 12: STORE
- Decode and execute → Program counter (PC): next box
- Decode and execute → Input and output: lesson S0.2
A teaching machine with sixteen memory boxes. Real processors have more registers and more boxes, and run the same loop.
Notice what the picture does not have. No wire says "this box is an instruction". The program and the data sit in identical boxes. Only the PC tells them apart, and the rules below come back to that.
Four Rounds, Worked by Hand
Now be the processor. The PC starts at 0. Each row below is one round of the loop.
| Round | PC | Fetch | Decode | Execute | Afterwards |
|---|---|---|---|---|---|
| 1 | 0 | box 0 holds 26 | 1 × 16 + 10: LOAD 10 | copy box 10 into A | A = 5, PC = 1 |
| 2 | 1 | box 1 holds 43 | 2 × 16 + 11: ADD 11 | add box 11 to A | A = 12, PC = 2 |
| 3 | 2 | box 2 holds 60 | 3 × 16 + 12: STORE 12 | copy A into box 12 | box 12 = 12, PC = 3 |
| 4 | 3 | box 3 holds 0 | 0 × 16 + 0: HALT | stop | the machine rests |
After four rounds, box 12 holds 12, which is 5 + 7. The processor never knew it was adding two numbers. It fetched four numbers and obeyed each one.
The Rules
Rule 1: Memory is numbered boxes.
The address says which box. The content is the number inside. They are different numbers.
Rule 2: A program is numbers in memory.
Instructions and data sit in the same kind of box. This is called the stored-program idea.
Rule 3: The PC points at the next instruction.
After each instruction the PC moves on by one. This machine has no other way to change it.
Rule 4: The loop never changes.
Fetch the number the PC points at. Decode it. Execute it. Step the PC. Repeat.
Rule 5: Only the PC decides what is an instruction.
A number is an instruction at the moment the PC arrives at its box. At any other time it is data.
Sources for These Rules
The parts of a computer: the textbook "Computer Organization and Design" by Patterson and Hennessy, section 1.4. It lists five parts, because it splits the processor in two and counts input and output separately.
The stored-program idea: the same book, sections 2.1 and 2.5. Also the textbook "Digital Design and Computer Architecture" by Harris and Harris, section 6.4.6.
The four instructions and the "kind times 16" rule are our own teaching machine. No real processor uses them.
Now Run It
The lab at the end of this page is this machine in about forty lines of SystemVerilog. One clock edge runs one round of the loop. This is what it printed.
pc=0 fetched 26: LOAD 10 A=5
pc=1 fetched 43: ADD 11 A=12
pc=2 fetched 60: STORE 12 box 12 now holds 12
pc=3 fetched 0: HALTCompare it with your hand table. The PC goes 0, 1, 2, 3. The fetched numbers are 26, 43, 60 and 0. A reaches 12, and box 12 receives it. The simulator did exactly what you did.
Now watch rule 5 bite. Suppose the programmer forgets the HALT, and box 3 holds a data value, 43, instead.
pc=2 fetched 60: STORE 12 box 12 now holds 12
pc=3 fetched 43: ADD 11 A=19
pc=4 fetched 0: HALTThe PC arrived at box 3 and found 43. The processor did what 43 says: ADD 11. A became 19, and nothing warned anyone. It stopped at box 4 only by luck: the lab sets unused boxes to 0, and 0 means HALT. A processor that wanders into data obeys the data.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys |
|---|---|---|
| Keep the program in memory, as numbers | Wire each job into the circuit | A new job needs new numbers and no new circuit. |
| Keep a few registers inside the processor | Work on memory boxes directly | A register is a few flip-flops whose value is there at once. Picking one box of sixteen takes a 16-to-1 multiplexer. Picking one of billions takes far more gates in a row, so memory answers later. |
| Make each instruction tiny | One huge instruction per job | A tiny step needs little circuit. Big jobs become many small steps. |
The second row has a cost. Every number the processor wants must first be loaded from memory, and every result must be stored back. Remember that. In later lessons, most of what moves along a chip's wires is these loads and stores.
At Scale
This section looks ahead. Skip it on a first reading if you like. A real processor is the sixteen-box machine grown larger, with one sort of instruction added.
More boxes
The processor studied in this track uses addresses that are 32 bits wide. Two to the power 32 is about four billion, so it can name four billion boxes.
More registers
Our machine has one working register, A. The processor in this track has 32 of them, so fewer numbers must travel to memory and back.
A public rule book
That processor follows RISC-V, said "risk five". RISC-V is a rule book that anyone may read and build to. It lists a processor's instructions and says what each one does.
More instructions, same jobs
A real processor has dozens of instructions. Nearly all of them still move a number, or do arithmetic on numbers.
The one addition: a jump
A jump is an instruction that puts a new number into the PC. A "JUMP 0" would send our machine back to box 0. Jumps let a program repeat steps and choose between them. Lesson S0.6 shows them. The practice problem "Write the Program" lets you use one now.
The two numbers above, 32 registers and 32-bit addresses, are RISC-V facts, taken from that rule book.
Try It
Run the lab. Match each printed row to one round of your hand table.
Change box 11 from 7 to 9. Predict the STORE row before you run it.
Replace the HALT in box 3 with the data value 43. Predict what the processor does when the PC reaches box 3.
Write a program that doubles box 10. You need only LOAD, ADD and STORE.
pc=0 fetched 26: LOAD 10 A=5 pc=1 fetched 43: ADD 11 A=12 pc=2 fetched 60: STORE 12 box 12 now holds 12 pc=3 fetched 0: HALTCheck Yourself
Common Mistakes
Wrong Read LOAD 10 as "put the number 10 into A".
The 10 is an address. The instruction copies the content of box 10.
Fix Look in box 10 first. A receives what is inside, which is 5.
Wrong Assume the processor knows which boxes hold instructions.
Every box holds a plain number. Only the PC decides which one is executed.
Fix End a program with HALT, so the PC never walks into data.
Wrong Picture the program as wiring inside the processor.
The wiring is the same for every program. The program is content in memory.
Fix To change the job, change the numbers in memory.
Remember
- A computer has three parts: memory holds numbers, the processor obeys instructions, and I/O touches the outside world.
- An address says which memory box; the content is the number inside. They are different numbers.
- A program is a list of instructions stored in memory as numbers, in the same kind of box as data.
- The processor repeats one loop: fetch the number the PC points at, decode it, execute it, step the PC.
- Nothing marks a box as an instruction. Whatever the PC points at gets executed.