Figure 5.1 Symbols for a NOT gate
This is an alternative to the wordy description of how a gate works. It simply lists all the possible inputs to the gate together with the corresponding outputs. The truth table for a NOT gate is really easy. There are only two possible inputs: 0 and 1 as we can see in Figure 5.2.
Figure 5.2 The truth table for a NOT gate
So, how is it used in the microprocessor?
The truth table only shows what happens to a single bit but in the microprocessor we may want to use a NOT gate to invert a hex number like A4H. In this case the hex number is first converted to an 8-bit binary number. This process is not performed by the microprocessor but by other external circuits. By the time it reaches the microprocessor it has been converted to the binary equivalent of 101001002.
The NOT gate has only one input so, to handle an 8-bit binary word, we will need eight NOT gates. Now it becomes much easier. Each NOT gate inverts just one of the bits and all the outputs are grouped together to form a new hex number. See how it works in Figure 5.3. The result was the hex number 5BH. This is curious. If we add A4H to this result of 5BH we get FFH or all ‘ones’ in binary, 111111112. There was nothing special about the number A4H. It happens with any pair of numbers generated by NOT gates. Why is this? Figure 5.3 gives a clue.
Figure 5.3 Inverting a hex number
A little extra bit
We can show an inversion by drawing a line over the top. In Figure 5.2 the input was given the letter A and the output was shown as X. We could say: X=.
Unlike the NOT gate, an AND gate has more than one input. In fact we can have as many inputs as we like but the good news is that in microprocessors only two inputs are used. This simplifies the symbols and the truth tables considerably.
An AND gate is any circuit that gives a logic (or binary) 1 if (and only if) every input to the circuit is at logic 1. So in microprocessors, with only two inputs, it is easier to say that it gives a 1 out if both of the inputs is at logic 1. The symbols for the AND gate are shown in Figure 5.4.
Figure 5.4 Symbols for an AND gate
The truth table in Figure 5.5 has four rows to cover all the possible combinations of inputs.
Figure 5.5 The truth table for an AND gate
What is the point of an AND gate?
We often meet an AND gate without realizing it. When we climb into an elevator the door must be closed AND the floor button pressed before the motor will start. This is an AND gate in action. In a microprocessor, groups of AND gates are used to handle pairs of inputs at the same time just like we did with the NOT gates. For convenience we usually use hex numbers to describe groups of inputs and outputs but remember it’s all really happening in binary.
Unless we appreciate that the hex numbers are really just groups of ones and zeros, it may seem odd to talk about putting numbers through AND gates. Figure 5.6 may make it (a little) clearer. In this figure, we have used hex inputs of 37H and 5BH giving a result of 13H. Note that the AND gate does not add numbers.
Figure 5.6 An AND gate in action
A little extra bit
In data books and manuals, the AND function is abbreviated to a dot like a period (full-stop). So, if an AND gate had two inputs called A and B and an output called X, then we could write X = A·B
Sometimes it is further simplified to X = AB
Very occasionally we come across a symbol ∧ so we can write X=A∧B.
The word NAND is just a fancy contraction of NOT and AND. The NAND gate is just an AND gate followed by a NOT gate so all the outputs shown in the AND truth table are just inverted by the NOT gate.
On a diagram, this combination is indicated by putting a small circle on the end of the symbol. The symbol and truth table are shown in Figure 5.7.
Figure 5.7 The truth table for a NAND gate
It is better not to make a big effort to learn the NAND gate. Just remember that it’s the same as the AND gate except the output has been inverted by the NOT gate that has been added internally. The symbol has a line over the top to indicate the added NOT function. A two input NAND could be written as X= or X=
or very occasionally X=
.
This follows on nicely from the AND gate. The OR gate gives a logic one at its output if either (or both) of the inputs is at a logic one. Just like the AND gate, the OR gate can have as many inputs as we wish but in a microprocessor, we only use two input versions. Its symbols and truth table are shown in Figures 5.8 and 5.9.
Figure 5.8 Symbols for an OR gate
Figure 5.9 The truth table for an OR gate
Another extra bit
The OR function can be written as + or sometimes ∨. So, if an OR gate had two inputs called A and B and an output called X, then we could write X=A+B or X=A∨B. Don’t mistake this + sign as ‘plus’ as in addition 3+4=7.
As we would expect, this is just the same as the OR gate except for the NOT gate added to the output. The symbol has the inversion line over it to give X= or
(see Figure 5.10).
Figure 5.10 The NOR gate
This is called the Exclusive-OR gate, which is abbreviated to XOR or EOR. Here are two examples of everyday English, both using the word ‘or’.
We get into an elevator and the operator says to us ‘Do you want to go up or down?’ We have a choice, we can decide to go up or we can go down. We have two possible answers – ‘up’ or ‘down’.
On the way home we buy a burger. We are asked ‘Do you want ketchup or mustard?’ This time we could answer ‘ketchup’ or ‘mustard’ or we could say ‘both’.
Figure 5.11 The XOR or difference gate
This is a fine example of how we can make something which is really easy appear difficult. The word ‘or’ in English has two different meanings which can be referred to as exclusive and inclusive. The first example used the exclusive ‘or’ because we could have one or the other but not both. The second situation uses the inclusive ‘or’ because we could have one or the other or both. We use both meanings everyday and understand them so well that we know automatically which one is meant.
In the XOR gate the output is a logic one if either input is a logic 1 but not both. Only two-input XOR gates are manufactured, whether for use in a microprocessor or not (see Figure 5.11).
To look at it in another way, the output from an XOR is a logic one if the two inputs are different. For this reason, it is often called a ‘Difference’ gate.
The electronic padlock
When we want to take some money out of our bank account we can go to the money machine and pop our card in. It then asks us to key in our code number which is usually a four-digit number. If the number is correct, we have access to our account.