Using the gates presented in the previous lesson, computer engineers can construct more complex pieces of logic. These pieces are called circuits, and they form the "brain" of a computer. In this lesson, we will learn about three important circuits: the decoder, the latch, and the adder.
Decoders are circuits for selecting based on a particular value. The simplest decoder is one that takes a single binary input (0 or 1) and selects between two options based on the input. To illustrate, consider the following example from Chris Crawford [1985]:
"Suppose, for example, that we have a wire. It can carry a 1 or a 0. Thus, one wire can represent one of two choices. We could, for example, use it to select one of two light switches that we might want to turn on. In other words, if the wire has a 0 on it, then we want to turn on light #0, and if it has a 1 on it, then we want to turn on light #1. However, there's a problem: the wire by itself can't turn on the right switch. If we hook it up directly to a light, it will turn the light on when we have a 1 on it, and turn it off when we have a 0 on it. We need a decoder. A decoder for this job might look like this:
If you put a 1 into this decoder, Output #0 will have a 1 on it and Output #1 will have a 0. If you put a 0 into this decoder, then Output #0 will get a 1 and Output #1 will get a 0." Since this decoder has one binary input, it is called a 1bit decoder.
Click on the button below to launch the circuit simulator applet [Arase 1999]. Use the applet to build the decoder illustrated in the diagram above. To test the behavior of your decoder, you will need to connect a power source, a toggle switch, and some LEDs to the circuit. The finished decoder should look similar to the picture below.
Larger decoders can be built to select among a greater number of options. A 2bit decoder, for example, has two binary inputs and four outputs while a 4bit decoder has four binary inputs and eight outputs. Crawford [1985] explains: "The twobit decoder looks at two wires to select one of four possible options. If you have two wires carrying 1s or 0s, then there are four possible combinations of the 1s and 0s: 00, 01, 10, and 11. If you can read binary, you will recognize these numbers as just decimal 0, 1, 2, and 3. Three wires would give eight combinations; eight wires would give 256 combinations."
The circuit diagram below represents the logic for a 2bit decoder. When a low voltage (represented by 0) is placed on both inputs, then a high voltage appears on Output W while the remaining outputs show a low voltage. Just like we described the behavior of gates with truth tables, we can also describe the behavior of circuits with truth tables. The truth table below describes the behavior of the twobit decoder when a low voltage is placed on both inputs. The remaining cases are left blank as an exercise. Launch the circuit simulator applet again, and use it to fill in the remainder of the truth table. The applet will display a model of a twobit decoder with LEDs attached to the four outputs. The inputs are controlled by the two toggle switches. Whenever an output (or input) has a high voltage, the associated LED will glow red.
Twobit decoder  Partial truth table  


Latches are another important circuit in computers. While decoders are used for selecting, latches are used for remembering. The circuit diagram below shows a simple latch made from two NAND gates. The NAND gate stands for "Not AND" and the behavior of this gate is exactly the opposite behavior of the AND gate. The truth table for the NAND gate is displayed on the diagram inside each gate. Notice that this gate has a small circle at the end of the gate just like the NOT gate to represent inversion. Also notice that some of the lines in the diagram cross but are not connected. Only lines with a black dot at their intersection are logically connected.
Crawford [1985] describes the behavior of the latch as follows: "Suppose that you start off with both inputs ('Remember 0' and 'Remember 1') set to 1. If you then make the 'Remember 0' wire equal to 0, then the output wire will be 0. If you make the 'Remember 1' wire 0, then the output wire will be 1. More important, after you stop making one of those wires 0, and revert to the normal state in which both wires are 1, then the output will still reflect the state that you put it into earlier." The animation below illustrates this behavior. The two push buttons represent switches which temporarily change the input from 1 to 0. Press one of the switches and trace how the change of input affects the circuit. Once the "Output" value has changed, the circuit continues to remember the new value even though the inputs have reverted to 1.
Latches like the one illustrated above provide one way of creating memory for a computer. With one latch, only a single bit can be remembered. However, by grouping latches together, much larger memories can be created. The diagram below illustrates a byte of memory created from eight latches. Because latches are extremely small, millions of them can be placed on a computer chip no larger than a dime! [Brookshear 1997].
Another circuit which is fundamental to computers is the adder. This circuit is responsible for binary addition. Before looking at the circuit, it will be helpful to review the four basic rules of binary addition. We can actually think of these four rules as a truth table with the slight exception of the fourth rule. Notice that the fourth rule causes a carry.



Rules of binary addition  Truth table for binary addition 


References
 Arase, K. (1999), "Simcir the circuit simulator," http://www.tt.rim.or.jp/~kazz/simcir/simcir.html.
 Brookshear, J. G. (1997), Computer Science: An Overview, Fifth Edition, AddisonWesley, Reading, MA.
 Crawford, C. (1985), "How Computers Work," http://www.erasmatazz.com/library/You_Should_Learn_to_Program/Appendix.html