How Computers Work from the transistor up · chapter 07
07Remembering a Bit
Chapter 6 ended on a confession, and this is the chapter that pays it off. Everything we've built so far shares one trait we never said out loud — every gate, every adder, the whole ALU. It has no past. Its output is a pure function of the inputs sitting on its wires right now. Set the operands and the answer appears. Change them and the old answer is gone without a trace. That property has a name: combinational logic, logic that only ever reacts. It's exactly why a calculator can't remember the number you just computed. So here is the strange question this chapter turns on: how can a machine made entirely of parts with no memory ever remember anything? The answer is almost insultingly small. It's a single wire bent back into a loop. When a gate's output feeds its own input, the machine stops being a function and starts having a history. The same inputs can now give two different outputs, depending on what happened before. That broken determinism isn't a bug. It is memory — the first thing in this whole course that can hold a value on its own. We'll watch an OR gate latch itself to 1 and refuse to let go. We'll build the cross-coupled SR latch that rests in either of two stable states, then gate it so it stores only on command. And we'll finish on the one flaw it can't shake: it listens too much. That flaw is the exact door the clock walks through next chapter. No magic in any of it — just a wire, doing something we've carefully never let a wire do until now.
01When a wire feeds itself
Before we break it, let's be precise about the thing we're breaking, because the whole chapter is a contrast against it. Take any gate we've built — say an AND. Notice its defining virtue: it is a function. Give it the same two inputs a billion times and it hands back the same one bit a billion times. No drift, no history, no "it depends." Its output is decided entirely by the inputs present this instant. That's determinism, and every truth table quietly assumes it — one row per input combination, one fixed answer each. Run a whole tape of chips through the same gate below and watch them all drop the identical colour. There is no yesterday in here.
A gate has no dice inside and no memory. Set A and B, predict Y, then hit Run again and again. Watch the disagreement count.
0 runs — predict Y, then Run
Fig. 1. A logic gate is a function on {0,1} — it maps a pair of bits to one bit, and that map is fixed. Pick a gate, set A and B, then hammer Run: every chip on the tape drops the same colour, the run count climbs into the dozens, and the disagreement tally stays nailed to 0. No dice, no drift, no memory of the last run — the hundredth press answers exactly like the first. That perfect repeatability is the whole reason a billion of these can stack into a computer: change an input and you ask a new question, but ask the same question and a gate can never change its mind.
Now pick the one gate we're about to abuse, and study its temper before you bend it, because its stubbornness is the whole trick. The OR gate lights its output the instant either input is 1. It goes dark in exactly one case: both inputs sitting at 0. Now read the rule a third time, as a warning. An OR with even one 1 anywhere on its inputs outputs 1 — nothing the other input does can argue it down. Flip the two inputs below and confirm it: one lit input is all it takes.
Both inputs at 0 — the only state where each input still has a vote. A single 1, on either pad, will force the lamp.
0 OR 0 → 0 · Q is free
Fig. 2. OR's push only goes up. Flip A and B: the instant either pad holds a 1, it's ringed in gold as the FORCER — that one input drives Q to 1 and the readout tells you the other is powerless. Only with both at 0 does anyone get a vote. Then take the challenge: A pinned at 1, your job is to make Q read 0. Every click lands on the failed-tries counter until the verdict concedes what the two tinted A=1 rows of the truth table said all along — OR has a forcing 1 but no forcing 0. It can raise its output; nothing can lower it. Hold that asymmetry: it is exactly the property the feedback loop is about to weaponise.
Before we bend any wires, let's try the honest route first. Chain gates one after another — a straight pipeline with no loops, the only shape we have ever built. Send a short pulse of 1 in and ask the chain to keep it. Each gate takes a moment to answer, so a deeper chain holds the pulse a little longer. Here is the question that decides everything: does longer ever become forever?
predict — will 8 gates hold it forever?
no pulse in flight — fire one ⚡
12345678↶
Each ▷ is a buffer — a gate that passes its input on, one gate-delay later. Fire a pulse and watch how long the chain remembers it. Then slide deeper and try again.
Fig. 3.More gates only buy a longer goodbye. Fire ⚡ a pulse into the 4-gate chain and watch the glow march one
buffer per tick: the counter climbs to “remembered for 4 gate-delays”, the lamp blinks once
— and then it’s gone, the output a pure function of the (now silent) input again. Make your call on the
predict chip, drag the depth to 8, and fire: 8 gates buy exactly 8 gate-delays, and the tally
strip stamps every run the same way — depth→delay, never hold. A straight chain can only postpone
forgetting, because the pulse always finds the end of the wire. Now press close the loop ↶: the output
wire bends around into the input, the chain becomes a ring, and the very same pulse circles lap after lap —
“held: forever — still circling.” The circuit is feeding itself its own answer, which is
exactly the move Fig 4 makes formal. Feedback isn’t one trick for remembering; it is the only door.
Here's the move we've spent six chapters never making. Take that OR gate and do something that should feel slightly illegal. Run its output wire back around and connect it to one of its own inputs. Now the gate is reading a signal it is itself producing. The same physical wire is both the answer and part of the question. Every circuit until now flowed strictly left-to-right, inputs to outputs — a clean one-way street. This one has a feedback loop, a cycle, and that single cycle is enough to change what a wire fundamentally is. Trace the loop below. Follow the output around and watch it arrive back at the input it feeds.
click a pad to flip its bit
One-way street — Q = A OR B. The signal crosses the gate, lights the lamp, and stops there. Nothing comes back.
Fig. 4. The move every earlier chapter refused to make. In one-way mode this is an ordinary OR gate: Q = A OR B. The signal starts at the pads, crosses the gate, lights the lamp, and stops — one direction, no way back, exactly like every circuit you have built so far. Now press bend it back. The output wire loops down, around, and into input B. Nothing has been added and nothing has been taken away: it is the same single wire, only now it is both the answer and part of the question, and the gate is reading what it just said. Hit trace the signal to send a pulse around and watch where it arrives. Flip the pads and follow the loop. What a cycle does to a circuit is the next figure's business.
Watch what that loop actually does, because it's the birth of memory and it happens fast. Leave the free input — call it Set — at 0. The output sits at 0, quietly feeding 0 back to itself: stable. Now pulse Set to 1 for even an instant. The output snaps to 1. And here's the thing: that 1 now travels around the loop and lands back on the gate's own input. So the OR keeps seeing a 1 coming in, even after you let Set drop back to 0. And an OR with a 1 on any input outputs 1. It holds itself up by its own bootstraps. Pulse it and let go — the 1 stays.
predict first: once you let go, is Q 0 or 1?
empty — output is 0
Fig. 5. The output wire loops back into the gate's own second input. Both inputs start at 0, so the OR puts out 0 — nothing. Now press & hold Set: one input goes high, OR fires, the output snaps to 1 — and that 1 races around the feedback loop into the gate. Here is the question. Answer it before you let go: the moment Set drops back to 0, where does Q land — back at 0, or still 1? Say it out loud, then release the button and watch. Then read on: Set is at 0, but the gate is still seeing a 1 on the loop, so it keeps outputting 1, which keeps the loop at 1, which keeps the output at 1… forever. Nothing is holding the input; the bit is holding itself. That circling 1 is the memory.
So we've built the simplest memory there is — and immediately hit its fatal flaw. It's worth feeling now, because the next section's whole design exists to fix it. This latch can remember a 1, beautifully, forever. But try to put it back. Drive Set to 0 and nothing happens. The loop is still feeding itself a 1, and the OR keeps outputting 1 no matter what you do to the free input. There is no wire you can wiggle to bring it home to 0. It's a write-once memory cell with no eraser: you can set it but you can never reset it. Try every input below and watch it refuse to come down.
Q = 0. Flip SET to 1 to write a bit.
rule: Q = SET OR fb · fb = 0 the two fb = 1 rows are out of reach — Q just follows SET.
the plug is the only way back — and pulling it is not a logic input.
An OR only ever pushes up. Its forcing value is 1: a single 1 anywhere on its inputs forces the output to 1 — so no value on any input can force a 0 out. To erase a bit with logic instead of a plug, we need the opposite: a gate whose 1 forces the output DOWN.
Fig. 6. An OR gate wired back into itself — the simplest thing that remembers. It has one free input, SET, and one input fed straight from its own output. Flip SET to 1 and Q jumps to 1; the feedback wire carries that 1 back in, so the fb column is now pinned at 1 — and of OR's four rows, only two of them have fb = 1. Both output 1. Drop SET back to 0 and Q doesn't budge, not because we failed to find the right combination but because there is no such row left to find: an OR only ever pushes up, never down. It's a write-once cell with no eraser; the only way back is to pull the plug. To erase with logic instead of a plug, we need a gate whose 1 forces the output down.
Now step back and notice the deep thing that just happened. It's the conceptual heart of the entire chapter, bigger than any one circuit. Look at the latch when Set is 0 — what is its output? The honest answer is: I can't tell you from the inputs alone. It might be 0 (if you never pulsed it) or 1 (if you did). Same input, two possible outputs. That is a flat-out contradiction of everything determinism promised. A truth table has one row for "Set = 0" and demands one answer; this device has two. The circuit has stopped being a function of its inputs. It's now a function of its inputs plus its own history. That's the line we just crossed, and it has a name: sequential logic, logic with a past. Set the same input and watch the output disagree with itself, depending on the road you took to get there.
now · S 0 R 0 — idle
…or poke it yourself (hold):
Q is unwritten — run a history to give it a value.
the truth‑table row for “S 0 · R 0”
S 0 · R 0→Q = ·after History A
S 0 · R 0→Q = ·after History B
Fig. 7.Determinism, shattered. A truth table promises one output for one input. Here the input is the same both times — S 0, R 0, perfectly idle — yet Q comes out 1 after you set it and 0 after you reset it. Nothing on the input lines changed; what changed is the past. The output feeds back into itself through those two crossed wires, so the circuit is now a function of its inputs and its history. That is the whole idea of sequential logic — and the first thing in this book that can remember.
If a truth table can't describe this thing, then the truth table is the wrong tool. Swapping tools is how you know you've genuinely entered new territory. A truth table has no axis for "when." But this circuit's whole behaviour is about when: its output depends on the order of things that happened over time. So we reach for the instrument that has time built in — the timing diagram. It draws each wire as a horizontal track, with time running left to right. You can literally see a 1 arrive on Set, watch the output rise in response, then see it stay high long after the input has dropped away. That persistence — a line staying up with no input holding it there — is memory made visible. Read the two tracks below left to right.
Set 1Rst 0Q 1
Set is high — it is forcing Q up to 1
Slide the now line across.
A truth table lists Set, Reset → Q and stops — but here Set=0, Reset=0 gives Q=0 early and Q=1 later. Same inputs, different output. Only when tells them apart, so we draw when.
Fig. 8. A truth table has a column for every input and none for when — so it can't describe a wire whose output depends on its own past. Switch tools: draw each wire as a track with time running left → right. Read the story: a short Set pulse snaps Q up — and Q stays high across the long stretch where Set has dropped back to 0, right until Reset knocks it down. Drag the now line (or click the tracks) and compare two instants where Set=0 and Reset=0: early, Q=0; late, Q=1. Identical inputs, opposite output. That gap is memory — and it only shows up once you give the picture an axis for time.
02Two stable homes — the SR latch
Our OR-latch works, but it's lopsided: one-way, no eraser. To fix it we need a mental picture of what "good" memory even looks like, and physics hands us the perfect one. Picture a ball in a landscape with two valleys and a hill between them. Leave the ball in the left valley and it stays there — nudge it a little and it rolls right back. Leave it in the right valley? Same story: the system has two resting places. Each one actively holds itself, and it takes a real shove to cross from one to the other. That's called bistability, two stable states, and it is the honest shape of a memory bit. 0 is one valley, 1 is the other, and small disturbances can't tip it between them. Push the ball around below and feel the two valleys hold.
So we want two valleys. Before we wire anything, though, ask a harder question: why did the OR-latch only ever have one? The honest answer isn't our wiring. It's OR itself. An OR input can do exactly one thing to the output: a 1 on it forces the output to 1. A 0 on it forces nothing at all — it just steps aside and lets the other input decide. So there is no value you can put on any OR input that drags a 0 out of it. OR only ever pushes up. That's why the eraser was missing: not because we weren't clever enough to find it, but because with OR it cannot exist. And that hands us the shopping list. We need a gate with an input that forces the output down. Now check NOR against that list, on the table you built in Chapter 2. Put a single 1 anywhere on a NOR's inputs and the output is 0. Every time, whatever the other input is doing. That is OR's rule held up to a mirror — OR's 1 forces high, NOR's 1 forces low. Hold that in your head, because the next five paragraphs lean on it. We didn't pick NOR. We deduced it.
stored bit: 0
resting in valley 0 — a stored 0
Drag the ball up a slope and let go — it rolls back. Only a shove big enough to clear the hill flips the stored bit.
Fig. 9. A ball in a landscape with two valleys and a hill between them — the honest physical shape of a memory bit. Valley 0 and valley 1 are the two stable resting states; each one actively holds the ball, so a small disturbance just rolls back. Grab the ball and drag it partway up a slope, or hit gentle nudge — the energy bar stays under the dashed barrier line and the valley pulls it home every time. Only a hard shove with enough energy to clear the hill flips the stored bit to the other valley, where it settles and holds just as stubbornly. That "two homes, a hill between, each holding itself" is bistability, and the next figure builds exactly this out of two cross-coupled gates.
The valleys picture hands us a test we can run on real gates. Take the smallest loop possible, a single NOT gate reading its own output, and count its resting places. Then add a second inverter to the ring and count again. The number of valleys is not a matter of taste; the gates themselves will tell us.
propose a resting value for Q
the loop must agree with itself
A resting value must survive its own gate.
Propose one, step, and see whether the loop hands the same value back.
The tally keeps score of which proposals survive — and how many there are.
0 · 1
the count of valleys
1 inverter · Q=0 · Q=1 · → ? stable
2 inverters · 10 · 01 · 00 · 11 · → ? stable
Fig. 10.Count the valleys — don't take the bit on faith. A resting state must survive its own gate.
On the 1 inverter tab, propose Q=0 and press step the loop: the gate stamps
NOT(0)=1 ✗ and flips it; try Q=1 and
NOT(1)=0 ✗ flips it back — keep stepping and the wire
simply buzzes, because the plank on the right never levels: an odd loop has 0 stable states (real chips
harvest that buzz as a ring-oscillator clock). Switch to 2 inverters and step all four (Q, Q′) proposals:
(1,0) and (0,1) close on themselves and lock, while (0,0) and (1,1) get corrected on
the first step and topple off the knife-edge into a valley. The tally lands the whole point: 0 stable, then
2 stable — the two valleys of Fig 8 were never a bolted-on metaphor. Two inverters is the smallest circle
that agrees with itself, it agrees in exactly two ways, and that pair of valleys is the bit — which is why the
SR latch is built from two cross-coupled gates.
Now let's build that ball-and-two-valleys out of gates. The trick is the same feedback we just discovered, done symmetrically so it works both ways. Take two of the gate we just deduced: two NOR gates. Keep both halves of its rule in your hand. A NOR is an OR with the output flipped, so it outputs 1 only when both inputs are 0 — and a single 1 anywhere on it forces the output to 0. Now cross-couple them: wire the output of the first into an input of the second, and the output of the second back into an input of the first. Each gate is now watching the other's answer. That mutual staring is the whole mechanism. The two outputs, which we'll call Q and its opposite Q̄, lock into being each other's opposite and stay that way. This is the SR latch, the canonical one-bit memory, with two control inputs left over: S (set) and R (reset). Trace the cross-coupling below.
HOLD — the loop is remembering Q = 0
Two pulses ride the feedback: Q leaves gate 1 and drops into gate 2 · Q̄ leaves gate 2 and climbs into gate 1. Each output holds the other in place.
press SET then let go — Q stays 1. That "staying" is memory. Hover a gate to light the wire it drives.
Fig. 11. Two NOR gates, each with its output wired straight back into the other's input — that mutual feedback is the whole trick. Watch the two pulses ride the loop. Q leaves gate 1 and drops into gate 2; Q̄ leaves gate 2 and climbs into gate 1. On the way the two feedback wires cross — the little hop shows they pass without touching. A 1 on any NOR input forces that gate's output to 0 — so whichever output is high is pinning the other one down, and the loop, once it settles, stays settled. Tap SET and let go: Q snaps to 1 and stays, even with your finger off. Tap RESET: it flips to 0 and stays. That refusal to forget is a single bit of memory. Raising S and R together is forbidden — it drives both outputs to 0, breaking the "always opposite" rule and, on release, leaving the winner to a coin-flip race.
Here's the payoff over the crippled OR-latch: this one erases. Pulse S to 1 and Q snaps to 1 and stays — set. Now pulse R to 1 and Q drops to 0 and stays — reset, the very move the OR-latch couldn't make. And when both S and R are back at 0, the latch simply holds whatever it last became. That's the full behaviour of a memory bit, in three modes: set it, reset it, or leave it alone and it remembers. Drive S and R below and store, erase, and hold a single bit with your own hands.
One thing before we open the hood, and it's the thing that makes the argument easy. Look at the latch in hold mode, with S and R both at 0. Each NOR now has one dead input — an input pinned at 0, which we just said forces nothing and steps aside. So what is a NOR with a dead input actually doing? Check it on the table you already have: NOR(0, 0) = 1, and NOR(0, 1) = 0. Feed a NOR a 0 on one input and it hands back the opposite of the other. That's an inverter. A two-input NOR with a dead input is quietly a one-input gate. Say that out loud, because it changes the picture completely: while the latch is holding, the SR latch simply is two inverters wired in a ring, each one's output feeding the other's input. Not a picture of it. The same device, with the dead inputs doing nothing. And two inverters in a ring is about the simplest object we could ever argue about.
both low — the bit holds its last value (0)
Tap a button for a quick pulse, or press and hold to drive the line yourself. Notice: the drive is momentary, but the bit stays put — that's memory. Set with S, reset with R, and with both low it simply remembers.
Fig. 12. A single stored bit, built from two NOR gates wired mouth-to-tail so each one's output feeds the other's input. Pulse S and the bottom gate is forced low, so the top gate rises — Q lights and reads 1. Pulse R and now the top gate is the one forced low — Q goes dark, 0. Now let both lines fall to 0 and watch the loop hold itself lit through the feedback: the bit stays. That third mode — hold — is the thing a bare OR-latch never had. (Drive both high at once and both outputs collapse to 0: not a valid bit, which is why a real memory cell forbids it.)
I don't want "it just holds" to feel like hand-waving, because the why is the most beautiful part. So let's watch the loop actually settle. Say Q is currently 1 and both inputs are 0. That 1 feeds into the second NOR, whose inputs are now (1, 0). A NOR with any 1 outputs 0, so Q̄ is 0. That 0 feeds back into the first NOR, whose inputs are now (0, 0). Both low, so it outputs 1, which is Q. And that's the 1 we started with. The state proves itself: each gate's output is exactly the input the other gate needs to keep producing it. The loop isn't just sitting still. It's a tiny argument that keeps reaching the same conclusion, faster than you can perturb it. That self-reinforcement is the ball settling into its valley. Step the signal around the ring below and watch it close on itself.
Predict first — of the four candidates, how many survive a lap?
With S = R = 0 both gates are left alone with each other. Four assignments of (Q, Q̄) are conceivable. Commit to a number first.
checked: 0 of 4
Fig. 13. The hold ring with S = R = 0: two NOR gates, cross‑coupled, each with its dead input pinned to 0 — and since a NOR with a 0 on one input just inverts the other, NOR(0, x) = NOT x. Gate 1 drives Q; gate 2 drives Q̄. Nothing outside is touching this loop, so the only thing holding the wires up is the wires themselves. Four assignments of (Q, Q̄) are conceivable — (0, 0), (0, 1), (1, 0), (1, 1). Predict how many of them the ring can actually hold, then load each one and Step it round: ask each gate what it really drives, and see whether the loop still agrees with what you assumed. What you find is the whole reason this circuit can store a bit.
Every honest engineer owes you the failure modes too, and this latch has one that textbooks love to skip past. We've used S, R, and both-low. What about both high — S = R = 1? Ask the latch to set and reset at the same instant and you get nonsense. Both NOR gates are forced to output 0, so Q and Q̄ are both0 — no longer opposites, which was the one promise the latch made. Worse, when you release both inputs together, the loop has no defined state to fall into. It can hang for a moment, balanced on the hilltop between the valleys. That's a real, physical condition called metastability: the ball teetering on the peak before it topples one way or the other. This is the forbidden input. It's not a bug in our drawing, but a genuine hole in the naive latch that better designs have to engineer around. Drive both inputs high below and watch the contradiction.
Click the R and S pads to drive them 0/1. Now set both to 1 — the forbidden input — then press Release both.
coin-flips so far — Q=1: 0 · Q=0: 0
Hold → Q = 0, remembered from before.
Predict first: if you drop one input at a time it's clean — so why is dropping both at once a coin‑flip?
Fig. 14. Two NOR gates wired mouth-to-tail — each output feeds back into the other — make a one-bit memory: S sets Q to 1, R resets it to 0, and with both low the loop simply holds whatever it last had. But drive both high and the contradiction shows: a NOR outputs 1 only when both its inputs are 0, so with a 1 on each gate both outputs are forced to 0 — Q and Q̄ are no longer opposites, and the whole idea of “the bit” falls apart. Worse is what happens on the way out. Drop one input and the latch lands cleanly. Drop both at the same instant and each gate sees 0, 0, each tries to rise to 1, each shoves the other back down — the loop teeters on the hilltop between the two valleys, and which way it finally topples is decided by noise too small to name. That is metastability: the naive latch has a real hole in it, and taming it is the first job of every clocked flip-flop that follows.
One more question the OR-latch let us dodge, and this one can't: what does the latch read the instant you switch the power on, before anyone has touched S or R? The unsettling truth is that nobody can say. Both gates power up at once, each racing to answer before the other has. Which valley the ball tumbles into is decided by microscopic differences between the two gates: a hair more delay here, a whisper of thermal noise there. It might come up 0, it might come up 1, and it can differ from one power-on to the next. That's why real memory is garbage until initialized — the very reason your programs must set a variable before reading it. The bit is real from the first microsecond; its value is meaningless until you write one. Power-cycle the latch below and watch it land on an unpredictable state.
landed 0power-upslanded 1
00 cycles0
Flip the switch — which valley will the bit fall into?
Same latch, same untouched inputs, every time. Yet the answer changes — because nothing wrote it. That’s why memory is garbage until you initialise it.
Fig. 15. The same cross-coupled latch, switched on again and again — with S and R both left at 0, untouched. At power-up both NOR gates start from zero and race to pull high first, and which one wins is settled by things you can’t see: a hair more delay in one gate, a whisper of thermal noise. So the ball tumbles off the hilltop into whichever valley it happens to fall — 0 one time, 1 the next. Nudge the gate mismatch and you tilt the odds, but never to a certainty. The bit is real from the first microsecond; its value is meaningless until something writes it. That is precisely why memory is garbage until initialised, and why your programs must set a variable before they dare read it.
03Storing on command
We can now store a bit — but look at how twitchy the storing is. The SR latch reacts to S and R the moment they move. Any glitch, any stray pulse on those lines, and the stored bit changes whether you meant it or not. That's no way to run a computer, where a hundred wires are settling and rippling at once. What we really want is control over timing: a way to say "ignore your inputs entirely, except during the exact window when I tell you to listen." So we add one more wire, an enable — call it C for control. It gates whether S and R can reach the latch at all. When C is 0 the latch is sealed and holds. When C is 1 it accepts input. Toggle the enable below and watch the same inputs get through or get blocked.
The enable tames when the cell listens. But we're still carrying that hole from earlier, and it's worth going back for. Look at where the forbidden input actually lived: one row. S = R = 1. That's all of it — every other combination behaves perfectly. So here's a question worth sitting with. What if we made that row unwireable? Not guarded against. Not written up in a footnote nobody reads. Physically impossible to ask for. Look at what it would take. S and R only break the latch when they agree. So don't let them agree. Run a single wire in, send it straight to S, and send it through an inverter on its way to R. Now R is always the opposite of S, by construction — the two can never both be 1, because there's no longer a wire to say it on. The forbidden row is off the map. Now look at what that did to the controls. Drive the new wire to 1 and the cell sets, so it stores a 1. Drive it to 0 and R goes high and the cell resets, so it stores a 0. It isn't giving an order any more. It is the bit. That's not a control line, that's data — so call it D. Two commands collapsed into one value, and the flaw didn't get engineered around. It got deleted.
Try it: set S = 1 with the enable SHUT — nothing moves. Now flip the enable OPEN and watch the bit store on command.
S — the set line
R — the reset line
S · R (what you asked for)1 · 0
reaching the latch (S·C , R·C)0 · 0
stored bit Q0
enable SHUT · inputs blocked · holding Q = 0
With C low, both AND gates output 0 no matter what S and R do — the latch sees hold and keeps its bit. Raise C and the gates pass S and R straight through. That's store on command.
Fig. 16. The raw latch was too twitchy — every wobble on S or R rewrote the bit. So we add one more wire, the enable C, and stand an AND gate in front of each input: the latch now sees S·C and R·C, not S and R. While C is low, both gates output 0 no matter how you jiggle the inputs — the latch reads that as hold and guards its bit. Raise C and the gates swing open, letting S and R through to set or clear the cell. Set S = 1 with the enable shut and nothing happens; flip the enable and the bit snaps into place. That is the whole trick of memory-on-purpose: it ignores its inputs except during the window you choose.
Now step back and read what we just built, because its behaviour has a shape you'll recognise. Forget the gates for a second and write down only what the cell does. When C is 1, Q takes the value sitting on D. When C is 0, Q keeps the value it already has. Two lines, and look at what they have in common. Each one hands you a value from one of two sources, and a control wire decides which source wins. A wire carrying a new value, a wire carrying the old value, and a line that picks which one comes out — that is a multiplexer, the 2-to-1 selector from Chapter 3, letter for letter. When the select is one way it passes input A; the other way, input B. We didn't import that. We derived the behaviour with our own hands and then found out it already had a name. Here's that MUX again so the shape is fresh in your hands. Flip its select and watch it choose between two inputs.
Flip C a few times and watch which row lights on each card. Then commit: are the two tables the same shape, or a coincidence?
THE MATCH — drawn when you commit
? ↔ ?
? ↔ ?
? ↔ ?
C = 1 · row 1 lit on BOTH cards
Two commands (S, R) became one value (D). A selector choosing between NEW and WHAT-I-ALREADY-SAIDis a memory cell — next figure we wire that loop for real.
Fig. 17. Two behaviour tables, one control. The left card is the cell we just built, stripped to what it does: C = 1 → Q takes D, C = 0 → Q keeps old Q. The right card is Chapter 3's selector, shrunk to the same two lines: sel = 1 → Y = leg B, sel = 0 → Y = leg A. Flip the single shared C at the bottom — one wire drives both cards — and the same row lights gold on both sides, every time. Commit a call (same shape, or coincidence?) and the match is drawn wire for wire: D ↔ leg B the new value, old Q ↔ leg A what it already said, C ↔ sel the chooser. Two commands became one value: a selector choosing between NEW and WHAT-I-ALREADY-SAID is a memory cell. We derived the behaviour with our own hands — and it already had a name.
So the same cell can be drawn a second way, and this drawing is the cleanest memory cell in the book. Take a MUX. Wire one of its data inputs to a fresh value we'll call D (for data). Wire the other data input — the feedback input — to the MUX's own output, looped back. The select line is our enable C, so read what that does. When C = 1, the MUX passes D through, and the cell takes the new value. When C = 0, the MUX passes the other data input instead — the one wired back to its own output. So it feeds itself its current value and holds. Be careful here, because the wording traps people. With the enable low the cell does not put out a 0. It puts out whatever Q already was. That feedback path is the memory. One data wire, one enable, and the feedback we've been circling all chapter. This is the gated D latch. It has no forbidden input — not by luck, but because we deleted that row ourselves: R is wired to be the opposite of S, so the two can never both sit at 1. There's no separate set/reset dance left either, because those two commands became one value. You just present a bit and say when — wire it below.
The loop is open — input 0 dangles, so with C=0 the MUX picks up nothing. Click the dashed wire to feed Q back into itself.
the new data bit — D
the enable C — which input the MUX takes
select C0
picks input0 · the loop
stored Q?
loop open · C=0 selects a floating wire
One MUX, fed its own tail. C=1 lets a fresh D wash straight through; drop C=0 and the output picks the loop — itself — so it just keeps re-choosing the bit it already holds. No illegal combo exists.
Fig. 18. A gated D latch is nothing but a 2:1 multiplexer wired to its own output. One input is fresh data D; the other is the latch’s own Q, looped straight back; the select line is the enable C. When C=1 the MUX passes D — the latch is transparent, Q simply follows the data. When C=0 it passes input 0 instead, which is Q feeding itself, so the output endlessly re-selects the bit it already carries — that circulating loop is the memory. Cut the loop and C=0 has nothing to hold, which is why the figure starts open and asks you to wire it. Unlike the raw SR latch, every combination of C and D is legal: there is no forbidden input.
Let's make storing a bit into a concrete, repeatable ritual, because this exact four-beat sequence is how every register you'll ever meet writes a value. To store a bit in the gated D latch: one — put the value you want onto D. Two — raise the enable C to 1, opening the door, and the latch takes D. Three — drop C back to 0, closing the door and locking the value in. Four — now you can change D to anything you like and the stored bit doesn't budge, sealed behind the closed enable. Present, enable, latch, release. Step through the store procedure below one beat at a time.
Beat 1 — PRESENT: pick the bit on D. The door is shut, so Q is untouched.
Fig. 19. Every register writes with the same four-beat ritual. Present the bit on D; the door is shut, so Q ignores it. Raise C (enable) and the door swings open — now Q copies D live, so toggle D and watch it follow. Drop C (latch) and the door shuts, freezing Q on whatever D was at that instant. Now release: flip D as much as you like — the door is sealed, and the stored bit doesn't move. That one locked door is how a wire remembers.
04The catch: transparency
We have a proper one-bit memory — and now I have to show you the crack in it, because being honest about this flaw is the entire reason the next chapter exists. Go back to step two of that ritual, the moment the enable C is high. During that whole window, what is the latch doing? It isn't taking a single snapshot of D. It's passing D straight through, live, continuously. Wiggle D while C is still 1 and the output Q wiggles right along with it, tracking every change like a plain wire. The latch is transparent: you can see clean through it to D for as long as the enable is held. It only truly "remembers" the value that happened to be on D at the instantC fell. Hold the enable high below and watch the output helplessly follow its input.
transparent — Q is just D, live
Hold the enable HIGH and wiggle D. Watch Q chase it with no will of its own. Only when you drop C to LOW does Q stop and keep the last value.
Fig. 20. A D-latch with its enable C held HIGH is transparent — the shutter is open, so D pours straight through to Q like a bare wire. Wiggle D (or hit auto-wiggle) and the scope shows Q tracing every move of D with a helpless, one-for-one copy — it isn't remembering anything, it's just passing it through live. Drop C to LOW and the shutter slams: D is walled off and Q freezes flat, keeping exactly the value that happened to be present the instant C fell. That falling edge — not the whole time C was high — is the only moment a latch actually decides what to remember.
Now feel why that transparency is a real problem and not a curiosity. Put it on a timing diagram, where the danger is obvious. Picture the output of our ALU wired to the D input of a latch, and imagine we hold the enable high for a stretch to "capture" the answer. But during that stretch the ALU's own output is still settling — carries rippling, bits flickering toward their final values. And because the latch is transparent, all of that churn passes straight to Q. We didn't store a value. We stored a live feed of a circuit mid-thought. The enable is high for a duration, but the thing we want to capture is a single trustworthy instant. That mismatch is the whole flaw. Watch the output smear across the transparent window below, when what we wanted was one clean sample.
how do we grab the bit?
window open 0.80 of the cycle → Q smeared through 7 glitches
while it's open, Q is transparent — it just copies D, churn and all.
A level-high enable is a duration. Everything D does during it leaks onto Q. We wanted one instant.
Fig. 21. Three waveforms in one compute cycle. D is the ALU's output: at the top of the cycle it churns — racing through half-formed intermediate values — before it finally settles and holds steady. EN is the enable, and the gold band is it held high — a window that stays open for a stretch of time. While that window is open the latch is transparent: Q simply copies D, so every glitch in the churn smears straight through onto the stored bit. Drag the window narrower and the smear shrinks; but the real fix is the toggle — switch to an instant and Q stops watching the whole duration and takes one sample at the closing edge, on the settled value, immune to the churn. That single active instant is exactly what a clock gives us — and it's where the next section begins.
Fig 19 leaves one tempting escape hatch: if the open window smears, just make the window shorter. Here is the circuit that slams that door. Wire the latch's own Q through a +1 circuit and back to D — the shape of every counter your computer owns. Then ask it to do the simplest job in arithmetic: count up by one.
how does the enable behave?
you meant +1 — open the window
a 3-bit counter: latch → +1 → back to the latch. one enable pulse should mean one +1.
runs stamped: 0
This is one loop. A chip has millions, and the fastest one beats any width you pick. Only zero width — an edge — beats them all.
Fig. 22. The lap trap. This 3-bit counter is a D latch whose output feeds a +1 whose output feeds the latch's own D — a ring. Press open the window ↻: while the enable is high the latch is transparent — a plain wire — so the new value races round the ring and increments again, once per lap, for as long as the window stays up. At full width the verdict stamps meant +1 · got +6: the machine lapped itself five extra times inside one pulse. Now drag the width down toward the loop's own delay (the gold loop ≈4 line on the strip) and press ↻ a few times: each run computes that run's loop delay fresh, and you'll collect +1 on one run and +2 on the next at the same width — every run stamps a dot on the width-vs-laps strip, so the unpredictability piles up in front of you. The pattern you just collected is the verdict on level-triggered storage: a safe window must be shorter than the loop's delay, and no width can promise that for every loop on a chip. Flip to edge capture and the scatter collapses to a single green column at +1 — a window of zero width is the only width that always works. Building a device that captures on an edge is exactly Chapter 8's job.
So the closing edge is the moment of truth: whatever D carries at that instant becomes the stored bit. One last honest question before we hand this chapter to the clock. What happens if D is mid-flip at the exact moment the door slams? The loop inside must choose a valley while the ball is still in the air.
D flips 0→1 at −64 ticks
clean capture — Q stores the 1
final values: —
Drag the slider (or the blue marker) into the shaded band, then run the trials.
The fence around the hilltop
The shaded band is setup · hold — the datasheet's keep-out zone: no D change allowed just before or just after the closing edge.
Below, the drop point on fig 8's landscape is set by how much head start the feedback loop got: a flip far from the edge drops the ball deep in a valley; a flip inside the band drops it near the hilltop, where each trial's simulated roll can teeter for a long, unpredictable time before toppling — that pile-up of slow settles is the histogram's ragged tail.
Fig. 23. Metastability never went away — the clock edge just cornered it. The top strip is the D-latch's last instant: C falls at centre, and you drag when D flips relative to that edge. Outside the shaded band the story is boringly deterministic: flip early and Q stores the 1, flip late and the old 0 survives — green verdict both ways, and the ball below drops deep into a valley. Now drag inside the band and press run 20 trials: each trial is a real simulated drop near the hilltop of fig 8's landscape, and while most settle fast, a few teeter visibly before toppling — the settle-time histogram grows a ragged tail, and the tally splits between 0 and 1, drifting toward a coin flip as you near the edge itself. That band — labelled setup · hold — is no bureaucratic fine print: it is the fence around the hilltop, the one strip of time where the feedback loop can be caught mid-decision. Every clocked circuit in the rest of this book keeps its D changes outside that fence, which is exactly why a whole machine can dare to move on one shared edge.
And that's Chapter 7 — the chapter where a wire learned to remember. The whole climb was one idea turned over and over: a feedback loop gives a circuit a past, and a past is memory. We watched an OR gate latch itself to 1 and shatter determinism — same input, two outputs, depending on history. That is precisely the definition of sequential logic. We drew it on a timing diagram, because a truth table has no room for "when." We built the SR latch from two cross-coupled NOR gates and watched it hold a bit in either of two bistable states. We were honest about its forbidden input, its metastability, and its garbage power-on value. Then we tamed it. An enable wire and a fed-back multiplexer gave us the gated D latch — a bit you store on command with one clean ritual: present, enable, latch, release. But we end exactly where every good chapter should: on a flaw we can't paper over. The gated latch is transparent the entire time its enable is high. It echoes its input live, so it can only faithfully capture a value at the single instant the enable falls. A memory that listens for a whole window, when we need it to listen for an instant, is a memory you can't trust to hold a computer together. So the question that opens the next chapter writes itself. What if the latch could only ever change at one razor-thin moment — the edge of a signal that ticks like a metronome — and stayed frozen the rest of the time? That signal is the clock. That device is the edge-triggered flip-flop, and eight of them side by side is a register — a machine word that holds still. That's where we go next.