← From gates to a processor

Combining gates

Wire one gate's output into another gate's input and you get a circuit. Work a circuit out row by row, each gate using only what arrives on its wires, then build circuits to match truth tables, even from NAND gates alone.

AND, OR and NOT are tiny. How do you get from three tiny gates to a whole processor?

In Why binary: logic gates each gate stood alone. Now wire them together: one gate's output becomes another gate's input. A few simple gates combined can make any truth table you like.

PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

OR, then NOT

A and B go into an OR gate. The OR gate's output goes into a NOT gate, which lights the lamp. Both switches are off. Is the lamp on?

TryTry it on the board and compare the result with your prediction.

Try: follow the wires

Was your prediction right?

Try it yourselfYour edits are saved in this browser.

Flip the switches to try all four rows. When is the lamp on?

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: row by row

Worked exampleBefore each step, say what you think comes next.
  1. gate 1: 1 OR 1=1\text{gate 1: } 1 \text{ OR } 1 = 1Gate 1 is wired from both switches.

Now do the row A = 0, B = 1 for gate 3.

In the four-gate circuit (OR, AND, NOT, AND), A = 0 and B = 1. What does gate 3, the NOT gate, output?

Sam works out the four-gate circuit. Click the line where it first goes wrong.

The four-gate circuit gives 1 when exactly one switch is on. Which gate does that on its own?

ModifyChange the problem on purpose and see what happens.

Vary: build to a table

Try it yourselfYour edits are saved in this browser.

Add gates and wire them so every row matches the wanted column (NAND: not both). Click a ● to wire from, then a pin to wire to.

Use the board. This ticks when you get there.

Now the lamp should light only when A is on and B is off.

Use the board. This ticks when you get there.

Only NAND gates this time, and one switch. Make a NOT. (Hint: both inputs can come from A.)

Use the board. This ticks when you get there.

Only NAND gates. Make OR.

Use the board. This ticks when you get there.

PractiseA few on your own, to check you have it.

Read the circuit

A goes into a NOT gate. Its output and B go into an AND gate. A = 0, B = 1. What is the output?

A and B go into a NAND gate; its output goes into a NOT gate. Which single gate is that the same as?

Review: a circuit has 3 switches. How many rows does its truth table have?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

Build XOR

Then: could you build XOR from NAND gates only? (It takes four.)

Try it yourselfYour edits are saved in this browser.
Need a hint?

XOR is 1 for "A or B", but not when both are on.

Another hint

One gate for "A or B", one for "both", then flip "both".

Another hint

OR, AND, NOT, then AND the OR with the NOT.

Build XOR (exactly one switch on) from AND, OR and NOT gates.

Use the board. This ticks when you get there.

For teachers

Students follow wired circuits row by row, then build circuits to match truth tables, including NOT and OR from NAND gates alone and XOR from AND, OR and NOT (AC9TDI8K04 node 3, extended; the kit names adder circuits as going further). About 45 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Try the boards yourself; wire by clicking a ● (from) then a pin (to), and click a wired pin to unplug it.

The one idea: each gate uses only what arrives on its own wires. Data representation's Why binary: logic gates is assumed (AND, OR, NOT, truth tables); start with a two-minute recap if the class hasn't done it recently.

This course is an extension (Years 9–10). Its lessons are tagged AC9TDI8K04 node 3 (why binary: circuits and logic gates), which the kit says adder circuits go further from.

Unplugged first works well: students as gates holding cards, passing 0s and 1s along strings.

Running the lesson

  1. Predict: students who said off are reading the switches, not the OR gate's output.
  2. Try: ask what one word describes this circuit (NOR, not-OR).
  3. Worked example: model the order: a gate can only be worked out once everything wired into it is known.
  4. Vary: after NOT from NAND, ask what A NAND A means in words.
  5. Make: compare circuits: did anyone use fewer gates?

The hard part (on purpose)

Wiring is fiddly at first and the first circuits don't match. Let the wanted column's crosses do the telling: students change one wire and watch which rows turn green.

When students get stuck

Stretch and support

Stretch: Build XOR from four NAND gates. Then: why would a chip factory rather make one kind of gate?

Support: Truth table cards for AND, OR, NOT and NAND to keep on the desk.

Where it leads

Next: Adding with gates (half and full adders).

Links: Data representation › Why binary: logic gates (the introduction). For keen students and teachers, the free course From NAND to Tetris (nand2tetris.org) builds a whole computer from NAND gates.

What each step is for

Now you can
Next lesson2. Adding with gatesAdding two bits is a truth table: the sum is XOR and the carry is AND, a half adder. A full adder also takes a carry in. One full adder per place, carries passed to the left, adds whole binary numbers.