4.6 Circuits That Select and Remember: MUX, Latch, Flip-Flop
Earlier, through the 4-bit adder, we saw how basic logic circuits combine to form a single functional block. But if the only circuit we had were an adder, a computer could do nothing but add. Depending on how we combine basic logic gates, though, we can build circuits with far more varied abilities — not just adding, but also picking one of several values or remembering a value. The aim of this section is to open your eyes to that variety of circuits. We’ll look in turn at the multiplexer (MUX), which picks one of several values; the latch, which remembers a value; and the flip-flop, the latch’s partner — and get a feel for how many different functions a circuit can hold.
First, the MUX (multiplexer). A MUX is a circuit that picks one of several inputs and sends it to its output. Think of a TV. Many broadcast channels come in at once, but the screen shows only the one channel you pick with the remote. In a MUX, the role of the remote is played by the control signal (the select signal).

Figure 4-7 (a) is a modularized MUX that picks one of four data inputs (D₀–D₃) and sends it to output Y. The reason there are two control signals, S₁ and S₀, is simple. As we saw in Section 4.3, two bits can make four combinations — 00, 01, 10, 11 — and each of these four combinations becomes a control signal meaning “pick D₀,” “pick D₁,” “pick D₂,” or “pick D₃.”
(b) is the detailed circuit diagram of the MUX drawn with basic logic gates. Each AND gate in the figure takes three inputs: one data input and two control signals. In Chapter 3 we only saw AND gates with two inputs, but just as we chained two transistors in a row, chaining three makes an AND gate with three inputs. The rule is the same: it outputs 1 only when all of its inputs are 1.
Here, the AND gates are used like gatekeepers. If we use the two inputs other than the data as “permission to pass” signals, then when both permissions are 1 the data passes straight through, and otherwise the output is always 0.
Each of the four AND gates opens its gate only when its own assigned control signal (a combination of S₁ and S₀) comes in. But an AND gate opens only when all its inputs are 1. So D₀’s gate, which must open when the control signal is 00, would never open if it received S₁ and S₀ as they are, since only 0s would come in. That’s why we also make inverted copies of S₁ and S₀ using NOT gates. A NOT gate outputs 1 when 0 comes in and 0 when 1 comes in. The AND gate in charge of D₀ receives these inverted values (S̄₁, S̄₀), so when the control signal is 00, both become 1 and the gate opens.
In this way, only the one AND gate whose gate is open lets its data through, and all the others output 0. But the AND gates still have four output wires, so we need a gate to gather them into the single output Y. The final OR gate does this. Since all the others are 0, the OR gate sends that one piece of data that passed through straight out to Y.
Table 4-4 is the truth table summarizing this behavior. If S₁=0 and S₀=0, D₀ is output to Y; if S₁=0 and S₀=1, D₁ is output; and so on — the selected input changes with the combination of control signals. Curious readers can trace the circuit themselves to check that the values in the truth table match.
| S₁ | S₀ | Y |
|---|---|---|
| 0 | 0 | D₀ |
| 0 | 1 | D₁ |
| 1 | 0 | D₂ |
| 1 | 1 | D₃ |
MUXes are widely used inside real CPUs too, to pick one of several operation results or register values and pass it to the next stage. They are a key circuit block that lets the entire flow of data be switched flexibly just by changing the control signal. That covers the MUX, the circuit that selects.
Next is the latch. A latch is a circuit that holds on to and remembers a 1-bit value. Compare a doorbell with a light switch. A doorbell rings only while you press the button and stops as soon as you let go. The adders and MUXes we’ve seen so far are like this too: their output is determined only by the inputs coming in right now, and they don’t remember earlier values (such circuits are called combinational circuits). A wall light switch, on the other hand, stays on after you flip it, even when you take your hand away. It remembers the last state it was set to. A latch is a circuit just like this light switch (a circuit that remembers earlier values like this is called a sequential circuit). As the name says, the key is to lock (latch) the value in place.
So how does a circuit remember? The secret is a feedback loop. In the circuits we’ve seen so far, signals flowed in only one direction, from input toward output. But if we send the output back toward the input, wiring it so that the returning signal reproduces the current output, the circuit keeps guarding its own output with the output it produces. Just as the light stays on after you let go of the switch, the circuit holds on to its current state by itself, without anything outside having to keep sending a signal.
There are several ways to make a latch; here we’ll look at the most basic one, the SR latch. In Figure 4-8, the left side (a) is the modularized representation, and (b) on the right is a latch circuit made from two NOR gates. NOR is the OR result inverted: it outputs 1 only when both inputs are 0, and 0 in every other case. In (b), the output Q of the upper NOR goes into an input of the lower NOR, and the output Q̄ of the lower NOR goes back into an input of the upper NOR. These two returning wires are the feedback loop. In the figure, Q is the output that gives the remembered value, and Q̄ (“Q bar”) is the output that always gives the opposite value.

In the circuit, S and R stand for Set and Reset. In light-switch terms, S is the “on” button and R is the “off” button. Normally neither button is pressed, which means S and R are both 0. If S alone is briefly made 1 (pressing the “on” button), output Q is set to 1; if R alone is briefly made 1 (pressing the “off” button), Q is reset to 0. And when you let go of the button so that S and R are both 0 again, the circuit holds on to the last state it was set to. In other words, press and release “on” (S) and Q stays at 1; press and release “off” (R) and it stays at 0. (Making S and R 1 at the same time is like ordering “turn on” and “turn off” at once, so it isn’t used.)
The value remains after you let go of the button precisely because of the feedback loop. Let’s trace it in Figure 4-8 (b). If Q is 1, that 1 goes into the lower NOR and makes Q̄ 0. When this 0 returns to the upper NOR, both of the upper NOR’s inputs (R and Q̄) are 0, so Q becomes 1 again. Q is 1 so Q̄ becomes 0, and Q̄ is 0 so Q becomes 1 again — in this way, the two gates hold each other’s outputs in place. When Q is 0, it stays at 0 in the same way.
So as long as power is supplied (the transistors inside the gates are connected to the power supply, as we saw in Chapter 3), this state is maintained. If we read the output voltage held this way as 0 or 1, following the agreement from Section 3.1, the latch is remembering 1 bit. It isn’t storing something inside; the two gates keep producing and guarding the voltage. (DRAM, which we’ll see later, works by storing charge.)
Beyond this, tweaking the SR latch a little makes writing a value easier. Figure 4-8 (c) shows how. First, the inputs are reduced to one. This input, called D after the first letter of Data, goes into the S side as is and into the R side inverted by a NOT gate. Second, the AND gatekeepers we saw in the MUX are placed in front of S and R, so that D reaches S and R only when E is 1. E comes from Enable, meaning “to let through.” Let’s call this a “gated latch.” Its formal name is the D latch (gated D latch).
When the gate is open (E=1), D immediately becomes S or R. If D is 1, S=1 and a 1 is written; if D is 0, R=1 and a 0 is written. Change D, and the written value immediately follows. When the gate closes (E=0), S and R both become 0, and the latch holds on to the value it had just before the gate closed. This is the same as the “let go of the button” state of the SR latch we saw earlier. So far we’ve looked at the SR latch, the basic remembering circuit, and the gated latch, a version tweaked to be easier to use.
The last circuit we’ll look at is the latch’s partner, the flip-flop. The difference between the two lies in “when the input is accepted.” A latch reacts the moment an input comes in. A gated latch is the same, as long as its gate is open. A flip-flop, on the other hand, is like a camera. It captures the input only at the instant a timing signal called the clock goes “click,” like taking a photo, and until the next “click” it keeps its output Q unchanged no matter how the input changes. We’ll cover the clock in detail in Section 4.7; for now, it’s enough to think of it as a signal that ticks at a steady beat inside the chip.
Figure 4-9 shows the outside and inside of a flip-flop. Seen from the outside, as in (a), its inputs are D and the clock (CLK), and its output is Q. Open it up, as in (b), and you find two of the gated latches we just saw, connected in a row.
But why two? With only one gate, while the gate is open the output keeps changing every time the input changes. What we want is to capture only the value at the single “click” instant. So we use two gates and make sure that when one opens, the other is always closed. Like the double doors at a building entrance, the two never open at the same time, so the input can’t pass all the way through to the output in one go.
In (b), the clock goes as is into the E of the back latch and inverted (NOT) into the E of the front latch. When the clock is 0, only the front gate is open and takes in the input; at the “click” when it becomes 1, the front gate closes and the back gate opens to take over that value. While the clock is 1 the back gate stays open, but because the front gate is closed, the value being passed on no longer changes. So no matter how the input changes, the output changes only at the “click.” Although there are two latches inside, the value stored is 1 bit. The front latch is a waiting room that briefly holds the next value, and the outgoing value Q comes only from the back latch.

Figure 4-10 shows the difference between a latch and a flip-flop as time flows. In the figure, time flows from left to right. The line in each row shows the value of that signal: just as we showed voltage with water levels in Section 3.1, a line that is up high means 1 and a line that is down low means 0 (1 and 0 are marked on the left of each row). The vertical dotted lines are the “click” instants.
The latch in the figure is a gated latch whose gate is kept open (E=1). So when the input changes, the value held by the latch follows immediately, but the flip-flop remembers only the input at each “click.” An input that briefly became 1 between click 1 and click 2 and then went back is missed entirely. At click 3 the input is 1, so the flip-flop remembers 1 and keeps it until the next click; at click 4 it newly remembers the input at that moment, 0.

In this section, going beyond the adder that calculates, we looked at a circuit that picks one of several values (the MUX) and circuits that remember a value (the latch and the flip-flop). What they do and how they’re built differ, but they have one thing in common: all are made by combining basic logic gates. The same gates become different circuits that calculate, select, or remember depending on how they’re connected — that is the point to take away from this section. In the next section, let’s look at the signal that announces the “click” moment the flip-flop waits for: the clock.