← From gates to a processor

Remembering a bit

Feed two gates' outputs back into each other and they hold a bit: a latch. Set makes it 1, Reset makes it 0, and with both off it keeps what it had. Latches side by side make a register that stores a number.

A gate's output changes the moment its inputs change. So how does a computer remember anything?

Every gate so far forgets: change its inputs and its output changes straight away. To remember, a circuit needs a loop: outputs fed back in as inputs.

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

On, then off

A latch has a Set switch and a Reset switch. Turn Set on: Q becomes 1. Now turn Set off again. What is Q?

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

Try: set it and let go

Was your prediction right? Follow the dashed wires: each NOR gate's output goes into the other.

Try it yourselfYour edits are saved in this browser.

Turn Set on, then off. Is Q still 1?

Use the board. This ticks when you get there.

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

Worked example: the latch's rules

Worked exampleBefore each step, say what you think comes next.
  1. S=1,R=0⇒Q=1S = 1, R = 0 \Rightarrow Q = 1Set: the bottom NOR's output goes to 0, which lets the top one make Q = 1.

Now try Reset.

Q is 1. Reset goes on, then off again. What is Q now?

Sam explains the latch. Click the line where it first goes wrong.

Why does RAM lose everything when the power goes off?

ModifyChange the problem on purpose and see what happens.

Vary: latches and a register

Try it yourselfYour edits are saved in this browser.

Set Q to 1, then reset it to 0, then turn both switches off. Does Q stay 0?

Use the board. This ticks when you get there.

Edge case: turn Set and Reset on together. What happens to Q and not Q?

Use the board. This ticks when you get there.

The register is four latches. Set the data switches to 9 and press Store.

Use the board. This ticks when you get there.

Now set the data switches back to 0 without pressing Store. What does the register hold?

Use the board. This ticks when you get there.

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

Memory

A register is 8 latches side by side. What is the biggest number it can hold?

A computer has 8 GB of RAM. About how many bits is that?

Review: which part keeps your files when the computer is switched off?

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

Hold a number

Then: what would you need to store 16 bits?

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

12 is 8 + 4.

Another hint

Set 1100, press Store.

Another hint

Then change the data switches to 0011 and don't press Store.

Make the register hold 12 while the data switches show 3.

Use the board. This ticks when you get there.

For teachers

Students set and reset a latch made of two NOR gates, see it keep its bit with both switches off, and store a number in a 4-bit register of latches (AC9TDI8K04 node 3, extended; the kit names adder circuits as going further). About 40 minutes.

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

Students will be able to

Before class

Try the boards yourself.

The one idea: a loop of gates keeps its bit. This is the first circuit whose output depends on what happened before, not only on its inputs now.

The board's register Store button stands in for a clock signal (a D flip-flop in real chips); the lesson keeps that detail out. Real RAM mostly uses capacitors (DRAM) rather than latches, with latches (SRAM) in caches and registers; both need power.

Running the lesson

  1. Predict: students who said 0 hold Sam's misconception; Try settles it.
  2. Try: ask which wire carries the memory.
  3. Worked example: trace the both-off row: what does each gate get?
  4. Vary: after both on, ask why designers avoid it.
  5. Make: ask what the register would hold after one more Store.

The hard part (on purpose)

Feedback is strange: an output that is also an input. Don't explain the NOR details first; let students see Q stay 1, then trace why.

When students get stuck

Stretch and support

Stretch: Look up a D flip-flop. How does it make sure the register changes only on the clock tick?

Support: A four-row table: S, R, Q after. Students fill it from the board.

Where it leads

Next: A tiny processor (fetch, decode, execute).

Links: Inside a computer (RAM empties without power; storage keeps data).

What each step is for

Now you can
Next lesson4. A tiny processorA processor repeats one cycle: fetch the instruction the program counter points at, decode it, execute it, one step per clock tick. The program is numbers in the same memory as the data. Step a tiny processor, change its program, and write your own.