← From gates to a processor

From gates to a processor: recap

For after the lessons: one card per lesson, to check what you remember. Answer each question in your head or on paper first, then check it. Nothing here is marked.

Building with gates

1. Combining gates

Try firstA and B go into an AND gate; its output goes into a NOT gate. What is the output for A = 1, B = 1, and what is this circuit called?

Check your answer

1 AND 1 = 1, NOT 1 = 0. It is NAND (not both).

Wire one gate's output into another gate's input and you get a circuit.

  • Work it out gate by gate: each gate uses only what arrives on its own wires.
  • Do that for every row of switches to fill the truth table.
  • Going the other way, you can build a circuit for any truth table from AND, OR and NOT, or from NAND gates alone.

XOR (exactly one on) is OR, AND and NOT combined.

Four gates make XOR: OR, AND, NOT, then AND. The output is 1 when exactly one switch is on.
Four gates make XOR: OR, AND, NOT, then AND. The output is 1 when exactly one switch is on.
Following a circuit · Sound on for the voiceover
Open the lesson →

2. Adding with gates

Try firstAdd 0110 + 0101 in binary. Which places carried?

Check your answer

1011 (11). Only the fours place carried (1 + 1 = 10).

Adding one column of binary is a small truth table.

  • Half adder (two bits): sum = A XOR B, carry = A AND B. So 1 + 1 = 10: sum 0, carry 1.
  • Full adder (two bits and a carry in): the sum is 1 when an odd number of inputs are 1; it carries when two or more are 1.
  • Put one full adder per place, each passing its carry to the left, and you can add whole numbers.

If the last carry has nowhere to go, the answer needs another bit: overflow.

5 + 7 in binary: one full adder per place, each passing its carry to the left. 0101 + 0111 = 1100 (12).
5 + 7 in binary: one full adder per place, each passing its carry to the left. 0101 + 0111 = 1100 (12).
Adding with full adders · Sound on for the voiceover
Open the lesson →

A machine that remembers

3. Remembering a bit

Try firstSet goes on then off, then Reset goes on then off. What is Q after each step, and why does the latch count as memory?

Check your answer

1, 1, 0, 0. With both switches off it keeps its last value, so its output depends on what happened before.

A gate on its own forgets. A latch is two gates whose outputs feed back into each other.

  • Set on: Q becomes 1.
  • Reset on: Q becomes 0.
  • Both off: Q keeps what it had. That is one bit of memory.

Put latches side by side and you have a register that stores a number until the next Store (in a processor, the next clock tick). They need power to keep going, which is why RAM empties when it's switched off.

Two NOR gates feeding each other hold one bit; four of them side by side store a 4-bit number.
Two NOR gates feeding each other hold one bit; four of them side by side store a 4-bit number.
A bit that stays · Sound on for the voiceover
Open the lesson →

4. A tiny processor

Try firstName the three steps a processor repeats, and say what the program counter does.

Check your answer

Fetch, decode, execute. The program counter holds the cell of the next instruction and goes up by one after each fetch (or jumps).

A processor repeats one cycle, one step per clock tick:

  1. Fetch: copy the instruction from the cell the program counter (PC) points at; add 1 to the PC.
  2. Decode: work out what the instruction means.
  3. Execute: do it (load, add, store, jump, output…).

The accumulator (ACC) holds the number being worked on. Instructions are numbers in the same memory as the data: a stored program. A 3 GHz processor ticks about 3 billion times a second.

Sixteen memory cells holding a program and its data, and a processor with a program counter, an instruction register and an accumulator.
Sixteen memory cells holding a program and its data, and a processor with a program counter, an instruction register and an accumulator.
Fetch, decode, execute · Sound on for the voiceover
Open the lesson →