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.

Five questions this page answers
Question
1What are the three parts of a computer, and what does each one do?
2What is an address, and how does it differ from the number stored there?
3A program is "stored as numbers". What does that mean?
4What does the program counter hold, and when does it change?
5Why 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.

PartWhat it isIts job
MemoryA long row of numbered boxes. Each box holds one number.Keeps the list of orders, and the numbers they work on.
ProcessorA 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

New words on this page
WordMeaning
MemoryA row of boxes. Each box stores one number. On this page a box holds eight bits: a number from 0 to 255.
AddressThe number of a box. Box 10 has address 10. The address says where. The content says what.
RegisterA row of flip-flops inside the processor that holds one number. The processor reaches it at once, with no address.
InstructionOne small order, such as "copy box 10 into register A". It is stored in a box as a number.
ProgramA list of instructions in neighbouring boxes.
Program counter (PC)The register that holds the address of the next instruction.
Fetch, decode, executeThe 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.

InstructionWhat it doesKind
LOAD nCopy the content of box n into A.1
ADD nAdd the content of box n to A.2
STORE nCopy A into box n.3
HALTStop.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.

What is in memory before the first clock edge
Box (address)ContentMeaning
026LOAD 10 (1 × 16 + 10)
143ADD 11 (2 × 16 + 11)
260STORE 12 (3 × 16 + 12)
30HALT
105data: the first number
117data: the second number
120data: the answer goes here

One Picture: One Round of the Loop

The Three Parts, and the Loop That Joins ThemStep through the picture. It starts with the three parts and ends with one full round of the loop.
  • Processor
  • Memory
  • Peripheral
CallValueReturnWaiting
The Three Parts, and the Loop That Joins ThemStep through the picture. It starts with the three parts and ends with one full round of the loop. component Program counter(PC) address of the nextinstruction component Decode andexecute works out what thefetched number asksfor component Register A the one number beingworked on component Memory, boxes 0to 3 the program: 26, 43,60, 0 component Memory, boxes 10to 12 the data: 5, 7, 0 component Input and output a switch, a lamp, akeyboard which box?the number in itLOAD, ADDSTOREnext boxlesson S0.2
  1. component Program counter (PC)address of the next instruction
    • which box? → Memory, boxes 0 to 3
  2. component Decode and executeworks out what the fetched number asks for
    • next box → Program counter (PC)
    • lesson S0.2 → Input and output
  3. component Register Athe one number being worked on
    • STORE → Memory, boxes 10 to 12
  4. component Memory, boxes 0 to 3the program: 26, 43, 60, 0
    • the number in it → Decode and execute
  5. component Memory, boxes 10 to 12the data: 5, 7, 0
    • LOAD, ADD → Register A
  6. component Input and outputa switch, a lamp, a keyboard
  1. 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.

  2. 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.

  3. Fetch

    The PC holds 0, so the processor reads box 0. The number 26 comes back.

    Follow the calls, values and waits
    1. data 26: Memory, boxes 0 to 3 → Decode and execute
  4. Decode

    The processor splits 26 into kind 1 and address 10, by the rule above. Kind 1 means LOAD.

  5. Execute

    LOAD 10 copies the content of box 10 into register A. A now holds 5.

    Follow the calls, values and waits
    1. data 5: Memory, boxes 10 to 12 → Register A
  6. 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.

Four rounds of fetch, decode, execute
RoundPCFetchDecodeExecuteAfterwards
10box 0 holds 261 × 16 + 10: LOAD 10copy box 10 into AA = 5, PC = 1
21box 1 holds 432 × 16 + 11: ADD 11add box 11 to AA = 12, PC = 2
32box 2 holds 603 × 16 + 12: STORE 12copy A into box 12box 12 = 12, PC = 3
43box 3 holds 00 × 16 + 0: HALTstopthe 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

  1. Rule 1: Memory is numbered boxes.

    The address says which box. The content is the number inside. They are different numbers.

  2. 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.

  3. 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.

  4. Rule 4: The loop never changes.

    Fetch the number the PC points at. Decode it. Execute it. Step the PC. Repeat.

  5. 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.

Printed by the lab. Each row is one round: the PC, the number fetched, what it decoded to, and the result.
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: HALT

Compare 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.

The same lab with box 3 changed from 0 to 43. Only the last three rows are shown.
pc=2 fetched 60: STORE 12   box 12 now holds 12
pc=3 fetched 43: ADD 11     A=19
pc=4 fetched 0: HALT

The 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 choiceThe alternativeWhat the choice buys
Keep the program in memory, as numbersWire each job into the circuitA new job needs new numbers and no new circuit.
Keep a few registers inside the processorWork on memory boxes directlyA 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 tinyOne huge instruction per jobA 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 page16 addresses
A 32-bit processorabout 4 billion addresses

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.

  1. 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.

  2. 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.

  3. 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.

  4. More instructions, same jobs

    A real processor has dozens of instructions. Nearly all of them still move a number, or do arithmetic on numbers.

  5. 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.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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: HALT

Check Yourself

Predict the outputThis program is given only as numbers. Decode each one (kind × 16 + address) and run it by hand. What is the last line the lab prints?
// A whole computer in one module: sixteen memory boxes and a processor
// with two registers. Each clock edge runs one instruction.
module tb;
  logic clk = 0;
  always #5 clk = ~clk;

  logic [7:0] mem [0:15];   // memory: sixteen numbered boxes, eight bits each
  logic [3:0] pc = 0;       // program counter: the address of the next instruction
  logic [7:0] a  = 0;       // register A: the one number the processor is working on

  // An instruction is a plain number: kind * 16 + address.
  localparam HALT = 0, LOAD = 1, ADD = 2, STORE = 3;   // named constants for the four kinds
  logic [7:0] word;         // the number just fetched
  logic [3:0] kind, addr;   // its two halves

  initial begin
    for (int i = 0; i < 16; i++) mem[i] = 0;
    mem[0]  = 27;
    mem[1]  = 42;
    mem[2]  = 44;
    mem[3]  = 61;
    mem[10] = 5;
    mem[11] = 7;
    mem[12] = 1;
    forever begin                      // repeat until the HALT case ends the simulation
      @(posedge clk);
      word = mem[pc];                  // FETCH: read the box the PC points at
      kind = word / 16;                // DECODE: split the number in two
      addr = word % 16;
      case (kind)                      // EXECUTE: do what the kind says
        LOAD:  begin a = mem[addr];
                 $display("pc=%0d fetched %0d: LOAD %0d    A=%0d", pc, word, addr, a); end
        ADD:   begin a = a + mem[addr];
                 $display("pc=%0d fetched %0d: ADD %0d     A=%0d", pc, word, addr, a); end
        STORE: begin mem[addr] = a;
                 $display("pc=%0d fetched %0d: STORE %0d   box %0d now holds %0d", pc, word, addr, addr, a); end
        default: begin                 // kind 0 is HALT; this model also stops on a kind it does not know
                 $display("pc=%0d fetched %0d: HALT", pc, word);
                 $display("box 13 holds %0d", mem[13]);
                 $finish; end          // $finish ends the simulation
      endcase
      pc = pc + 1;                     // step to the next box, and repeat
    end
  end
endmodule
ConceptBox 7 holds the number 50. What happens if the PC reaches box 7?
ConceptAfter ADD 11 runs in the worked program, which statement is true?
ConceptA chip must do a new job. With a stored program, what has to change?
ConceptIn this machine, which number in a box means LOAD 9?

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.

Practice

Report a problem with this page