Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [50]
This is a common way to label the separate bits of a multibit number. The bits A0, B0, and S0 are the least-significant, or rightmost, bits. The bits A7, B7, and S7 are the most-significant, or leftmost, bits. For example, here's how these subscripted letters would apply to the binary number 0110-1001:
The subscripts start at 0 and get higher for more significant digits because they correspond to the exponents of powers of two:
If you multiply each power of two by the digit below it and add, you'll get the decimal equivalent of 0110-1001, which is 64 + 32 + 8 + 1, or 105.
Another way an 8-Bit Adder might be drawn is like this:
The double-line arrows have an 8 inside to indicate that each represents a group of eight separate signals. They are labeled A7…A0, B7…B0, and S7…S0 also to indicate 8-bit numbers.
Once you build one 8-Bit Adder, you can build another. It then becomes easy to cascade them to add two 16-bit numbers:
The Carry Out of the adder on the right is connected to the Carry In of the adder on the left. The adder on the left has as input the most-significant eight digits of the two numbers to be added and creates as output the most-significant eight digits of the result.
And now you might ask, "Is this really the way that computers add numbers together?"
Basically, yes. But not exactly.
First, adders can be made faster than this one. If you look at how this circuit works, a carry output from the least-significant pair of numbers is required for the next pair to be added, and a carry output from the second pair is required for the third pair to be added, and so forth. The total speed of the adder is equal to the number of bits times the speed of the Full Adder component. This is called a ripple carry. Faster adders use additional circuitry called a look-ahead carry that speeds up this process.
Second (and most important), computers don't use relays any more! They did at one time, however. The first digital computers built beginning in the 1930s used relays and later vacuum tubes. Today's computers use transistors. When used in computers, transistors basically function the same way relays do, but (as we'll see) they're much faster and much smaller and much quieter and use much less power and are much cheaper. Building an 8-Bit Adder still requires 144 transistors (more if you replace the ripple carry with a look-ahead carry), but the circuit is microscopic.
Chapter 13. But What About Subtraction?
After you've convinced yourself that relays can indeed be wired together to add binary numbers, you might ask, "But what about subtraction?" Rest assured that you're not making a nuisance of yourself by asking questions like this; you're actually being quite perceptive. Addition and subtraction complement each other in some ways, but the mechanics of the two operations are different. An addition marches consistently from the rightmost column of digits to the leftmost column. Each carry from one column is added to the next column. We don't carry in subtraction, however; we borrow, and that involves an intrinsically different mechanism—a messy back-and-forth kind of thing.
For example, let's look at a typical borrow-laden subtraction problem:
To do this, we start with the rightmost column. First we see that 6 is bigger than 3, so we have to borrow 1 from the 5, and then subtract 6 from 13, which is 7. Then we have to remember that we borrowed 1 from the 5, so it's really a 4, and this 4 is smaller than 7, so we borrow 1 from the 2 and subtract 7 from 14, which is 7. Then we have to remember that we borrowed 1 from the 2, so it's really a 1, and then we subtract 1 from it to get 0. Our answer is 77:
Now how are we ever going to persuade a bunch of logic gates to go through such perverse logic?
Well, we're not going to try. Instead, we're going to use a little trick that lets us subtract without borrowing. This will please Polonius ("Neither a borrower nor a lender