What is inside a computer before it does anything: numbered memory cells, a byte of eight bits, the addresses a four-wire bus can give, and a program that is nothing but numbers in memory.
Step 1 of 5 · Sixteen cells
Step 1 of 5
Sixteen cells
Before a computer can work anything out, it needs somewhere to keep numbers. That place is the memory: a row of cells, each holding one number. To find a cell, each one gets a number of its own, its address, like house numbers on a street.
In the Scene a toy processor sits on a board. Look inside is open at Blocks: the lid is lifted, and to the right of the chip you can see the memory, sixteen cells with their addresses. The processor picks a cell by sending its address out on the address bus, a ribbon of parallel wires. A lit lane is a wire at high voltage, 1; a dark lane is 0. Each wire carries one bit.
Step 2 of 5
One byte
Every memory cell is a byte: eight bits. Read as a number in base two, each bit has a place value, right to left: . Add up the place values of the bits that are on, and you have the number. 0001 1100, for example, is , the number in cell 14.
The registers inside the processor, A and B, are eight bits wide too, so they also hold one byte each.
Step 3 of 5
A byte is a number
The memory does not hold only data. The program sits there too: the first five cells, addresses 0 to 4, are the instructions the processor will run, and the last two cells are the numbers the program adds. Nothing in a byte marks it as an instruction or a number. The labels on the memory are for us; the chip only ever sees bits.
Now the lid is closed. The byte at address 0 is 0001 1110. Read it as a number.
Step 4 of 5
Opcode and address
When the same byte is read as an instruction, it splits in two. The left four bits are the opcode: what to do. The right four are an address: which cell to do it to. Four bits are just enough for sixteen cells.
This chip has eight opcodes:
| Code | Instruction | What it does |
|---|---|---|
0001 |
LDA |
loads register A with what is in the cell |
0010 |
LDB |
loads register B with what is in the cell |
0011 |
ADD |
adds A and B, and the answer goes into A |
0100 |
SUB |
takes B from A, and the answer goes into A |
0101 |
STA |
writes A to the cell |
0110 |
JMP |
jumps to the address |
0111 |
JZ |
jumps to the address if the last answer was zero |
1111 |
HLT |
stops the processor |
So 0001 1110 is LDA 14: opcode 0001, load A, and address 1110, that is 14. The program in the Scene is LDA 14, LDB 15, ADD, STA 13, JMP 4: load the two numbers, add them, store the sum in cell 13, then jump on the spot for ever.
Step 5 of 5
Copy, don’t move
Clock tick stands at 1. The instruction LDA 14 is already in the instruction register, and on the next tick it will be carried out: address 14 goes out to memory, and the number in that cell comes to register A. Predict what will be left in cell 14 afterwards.
Loading the interactive version…
Loading the interactive version…
Each step sets up the Scene for you, and a control marked “fixed” stays put for that step.
Practice · Choose
The chip’s address bus is four lanes, and each lane carries one bit. How many different memory cells can it give an address to?
Practice · Choose
The chip’s address bus is four lanes, and each lane carries one bit. How many different memory cells can it give an address to?
Practice · Calculate
A memory cell, like each register on the chip, is one byte: eight bits. What is the largest number one byte can hold?
Practice · Calculate
A memory cell, like each register on the chip, is one byte: eight bits. What is the largest number one byte can hold?
Practice · Calculate
The byte at address 0 is 0001 1110. The lid is closed. Read as a number rather than an instruction, what is this byte?
Practice · Calculate
The byte at address 0 is 0001 1110. The lid is closed. Read as a number rather than an instruction, what is this byte?
Practice · Choose
Address 3 holds the byte 0101 1101. Opcode 0101 is STA, “store A”. What does the instruction do?
Practice · Choose
Address 3 holds the byte 0101 1101. Opcode 0101 is STA, “store A”. What does the instruction do?
Practice · Predict, then look
Cell 14 holds 28. Tick 2 carries out LDA 14. What will be left in cell 14 after the tick?
Practice · Predict, then look
Cell 14 holds 28. Tick 2 carries out LDA 14. What will be left in cell 14 after the tick?
Lesson complete. Every practice question here is done.