Computer memory has billions of slots that hold values, and a value is written only to the one slot that an address (a number) points to. What kind of circuit takes a single number and picks just one of many slots?
A circuit that takes an n-bit number and activates exactly one of several outputs is a decoder.
The simplest, the 2-to-4 decoder, takes a 2-bit input and sets just one of its 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 |
When the input AB is 00, O0 turns on; 01 turns on O1, 10 turns on O2, and
11 turns on O3. Each output can be built from AND and NOT. For example,
O0 = ¬A ∧ ¬B and O3 = A ∧ B.
Change A and B to try all four combinations. Only one output is ever on.
The decoder, which uses a number to turn on one of several outputs, and the MUX, which picks one of several inputs to output, are both circuits that select by number. Use a decoder to pick where to write and a MUX to pick where to read, and you can read from and write to one of many storage locations. We cover this in the register file.
In the next post, let’s combine gates to build a circuit that actually performs addition.
Add just two OR or NOT gates to a 3-to-8 decoder to build a circuit that outputs 1 when inputs A, B, and C are not all the same.