In the previous post, we learned that a single NAND gate can build every logic circuit. AND, OR, and NOT were all just combinations of NAND.
Every circuit we’ve built so far processes inputs in the same fixed way. But a real computer must behave differently depending on the situation. When adding, it sends data to the addition circuit; when subtracting, to the subtraction circuit. Sometimes it needs to pick one of four storage locations to read. What kind of circuit makes this selection possible?
Think of the channel buttons on a remote control. They pick one broadcast out of many and show it on screen. A multiplexer (MUX) is exactly that remote. It’s a circuit that selects one of several inputs and passes it to the output.
The simplest MUX picks one of two inputs: the 2-to-1 MUX. When the select signal S is 0 it outputs A; when S is 1 it outputs B.
| Out | |||
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
So when S is 0 it passes A through; when S is 1 it passes B through. In logic
notation: (NOT S AND A) OR (S AND B). We can build this from the gates we
learned before.
What if there are four inputs? Just widen the select signal to 2 bits (S1, S0).
A 4-to-1 MUX picks the first input for 00, the second for 01, the third
for 10, and the fourth for 11. It can be built by combining three 2-to-1
MUXes: S1 drives two MUXes that each narrow four candidates down to two, and S0
drives a third MUX that makes the final pick.
When you need to pick one of four data sources to read, a 4-to-1 MUX does the job. The 2-bit select signal corresponds to the source number.
Now we go in the opposite direction. A circuit that takes a single input and activates exactly one of many outputs is a decoder.
Think of elevator buttons. Press the button for floor 3 and only the floor 3 indicator lights up. One input, but only the corresponding output is activated.
The simplest 2-to-4 decoder takes a 2-bit input and sets exactly one of four outputs to 1.
| O0 | O1 | O2 | O3 | ||
|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 1 |
00 O0 is on, 01 turns on O1, 10 turns on O2, 11 turns on
O3. Each output is a combination of AND and NOT. For example,
O0 = (NOT A) AND (NOT B) and O3 = A AND B.Decoders will reappear as a key component inside the computer in later posts.
What happens when we combine a MUX and a decoder?
Suppose four storage locations each hold a different value. You want to pick one to read, or pick one to write a new value to.
MUX selects one of many inputs to output; a decoder activates one of many outputs from a single input. These two circuits point in opposite directions, yet both solve the same problem: selection.
In the next post, let’s combine gates to build a circuit that actually performs addition.