By the end of this chapter you should be able to:
- Show how altering the second operand of a full adder turns one adder into a unit performing transfer, increment, add, subtract and decrement.
- Combine an arithmetic section, a logic section and function-select multiplexers into a complete ALU slice, and read its function table.
- Work out the output and carry of a 4-bit ALU for a given operand pair and selection code.
- Explain how carry propagates between ALU slices, and why the carry chain must be broken during logic operations.
- Describe the organisation of the 74181 and the role of its mode, select, carry and propagate-generate pins.
- Derive the binary-to-Gray and Gray-to-binary conversion equations from a truth table and K-maps, and account for the difference in their propagation delay.
- Convert between BCD and binary in both directions, including a full trace of the shift-and-add-3 algorithm.
Part 4 has produced a collection of blocks — an adder, a comparator, a decoder, a multiplexer — each of which does one thing. A processor cannot afford one block per operation, because at any instant it is performing only one of them and the rest are idle silicon. What it needs is a single unit that performs whichever operation the instruction asks for, and that is the arithmetic logic unit. Building one turns out to require no new circuit at all: the adder of Chapter 16 already computes several different functions if you are willing to alter what you feed it, and a multiplexer of the kind Chapter 19 described chooses between the results.
The second half of the chapter takes the design procedure of Chapters 7 and 8 — truth table, K-map, minimal expression, gates — and applies it to code converters, the circuits that translate between the representations of Chapter 4. Two of them, binary to Gray and back, collapse into a handful of exclusive-OR gates and are worth deriving properly because the result is so much simpler than the truth table suggests. The other two, between binary and BCD, cannot be done with a fixed handful of gates, and the algorithm that does them is a good example of a design that is easier to reason about as a procedure than as a Boolean expression.
1 From the Adder to an Arithmetic Unit
Chapter 16 left us with a four-bit parallel adder that computes \(S = A + Y + C_{in}\) for two four-bit words \(A\) and \(Y\) and a carry into the least significant stage. It looks like a circuit that does one thing, but the useful observation is that \(Y\) and \(C_{in}\) are inputs like any others. If a small network sits in front of the adder and replaces \(B\) by something else before it arrives, the adder performs a different arithmetic operation without a single gate inside it being altered.
Four choices of \(Y\) are enough to be interesting, and all four are cheap: \(Y = 0000\), \(Y = B\), \(Y = B'\) (the bitwise complement) and \(Y = 1111\). Combined with the two values of \(C_{in}\) they give eight arithmetic functions:
| \(Y\) applied | \(C_{in} = 0\) | \(C_{in} = 1\) |
|---|---|---|
| \(0000\) | \(F = A\) — transfer | \(F = A + 1\) — increment |
| \(B\) | \(F = A + B\) — add | \(F = A + B + 1\) — add with carry |
| \(B'\) | \(F = A - B - 1\) — subtract with borrow | \(F = A - B\) — subtract |
| \(1111\) | \(F = A - 1\) — decrement | \(F = A\) — transfer |
The third and fourth rows deserve justification rather than assertion. Chapter 3 defined the two's complement of an \(n\)-bit word as \(2^n - B\), obtained by complementing every bit and adding one, so
The \(2^n\) is the carry out of the most significant stage and is discarded, leaving \(A - B\) in the four sum bits. With \(C_{in} = 0\) the same expression gives \(A - B - 1\), which is subtraction with a borrow already taken. For the last row, \(1111\) is the four-bit two's complement representation of \(-1\), so adding it decrements.
Reading the carry out takes a moment's care in the subtraction rows, because it is now a borrow indicator with inverted sense: \(C_{out} = 1\) means the \(2^n\) term appeared, which means no borrow was needed and \(A \ge B\). A student who reports a borrow whenever the carry output is high has the condition exactly backwards on half the class of problems.
Producing \(Y\) is a job for the multiplexer of Chapter 19. Four data inputs — the constant 0, the bit \(B_i\), the bit \(B_i'\) from an inverter, and the constant 1 — feed a 4-to-1 multiplexer per bit, all four multiplexers sharing the same two select lines \(S_1S_0\). The select word therefore names the arithmetic operation, and the whole arithmetic section is one adder, four multiplexers and four inverters.
2 The Logic Unit and the Function-Select Multiplexers
Arithmetic is only half of what an instruction set needs. The other half is bitwise logic — AND for masking, OR for setting bits, exclusive-OR for toggling and comparison, and complement — and these cannot be squeezed out of the adder, because the adder's whole purpose is to let information move between bit positions along the carry chain, whereas a logic operation must keep every bit position independent.
So the logic section is built separately and in the obvious way: for each bit, one AND gate, one OR gate, one XOR gate and one inverter, with their four outputs going to a 4-to-1 multiplexer driven by the same \(S_1S_0\) that steers the arithmetic section. A second, 2-to-1 multiplexer then chooses between the arithmetic result and the logic result under a mode input \(M\), and its output is the slice output \(F_i\).
The reason for a separate mode bit rather than simply widening \(S\) to three bits is worth stating, because it is the one place where the two halves interact. In logic mode the carry chain must be broken. If \(M = 1\) selected a logic function at the output multiplexer but left the adder running, the carry rippling along the slices would be meaningless — yet it would still be presented at \(C_{out}\), and any circuit downstream that tested it would be misled. Real ALUs use \(M\) to disable the internal carries as well as to steer the output multiplexer, which is exactly what the mode pin of the 74181 does.
Counting the hardware for a four-bit unit: one adder, twelve multiplexers and sixteen gates in the logic section — a great deal of logic to control with three pins, which is why the ALU was among the first functions offered as a single MSI package.
Three stages, in this order: a per-bit network that transforms \(B\) under control of the select word; an adder that is never reconfigured; and multiplexers that pick which of the available results reaches the output. Everything that follows in this chapter, and the 74181 itself, is a refinement of those three stages.
3 A Complete 4-Bit ALU and Its Function Table
Four of the slices of Figure 20.1 side by side, with the carry output of each driving the carry input of the next, make a four-bit ALU with twelve inputs — \(A_3\ldots A_0\), \(B_3\ldots B_0\), \(M\), \(S_1\), \(S_0\), \(C_{in}\) — and five outputs, \(F_3\ldots F_0\) and \(C_{out}\). Its complete behaviour is the twelve-row function table below.
| \(M\) | \(S_1\) | \(S_0\) | \(C_{in}\) | Operation | \(F\) for \(A=1011,\;B=0110\) | \(C_{out}\) |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | Transfer \(A\) | 1011 | 0 |
| 0 | 0 | 0 | 1 | Increment \(A\) | 1100 | 0 |
| 0 | 0 | 1 | 0 | Add \(A + B\) | 0001 | 1 |
| 0 | 0 | 1 | 1 | Add with carry \(A + B + 1\) | 0010 | 1 |
| 0 | 1 | 0 | 0 | \(A - B - 1\) | 0100 | 1 |
| 0 | 1 | 0 | 1 | Subtract \(A - B\) | 0101 | 1 |
| 0 | 1 | 1 | 0 | Decrement \(A - 1\) | 1010 | 1 |
| 0 | 1 | 1 | 1 | Transfer \(A\) | 1011 | 1 |
| 1 | 0 | 0 | × | \(A \cdot B\) | 0010 | — |
| 1 | 0 | 1 | × | \(A + B\) (OR) | 1111 | — |
| 1 | 1 | 0 | × | \(A \oplus B\) | 1101 | — |
| 1 | 1 | 1 | × | \(A'\) | 0100 | — |
Take \(A = 1011\) (decimal 11) and \(B = 0110\) (decimal 6).
Add (\(M=0\), \(S_1S_0 = 01\), \(C_{in} = 0\)). The operand multiplexers pass \(Y = B = 0110\), and the adder forms \(1011 + 0110 = 10001\). The five-bit result is one bit too wide for the output, so \(F = 0001\) and \(C_{out} = 1\). In decimal, \(11 + 6 = 17\), and \(17 = 16 + 1\): the carry carries the sixteen.
Subtract (\(M=0\), \(S_1S_0 = 10\), \(C_{in} = 1\)). The multiplexers pass \(Y = B' = 1001\), which is decimal 9, and the carry-in adds one. The adder forms \(11 + 9 + 1 = 21 = 10101\), so \(F = 0101\) and \(C_{out} = 1\). Decimal 5 is indeed \(11 - 6\), and the carry being 1 confirms that no borrow was required. With \(C_{in} = 0\) the same select code gives \(11 + 9 = 20 = 10100\), so \(F = 0100 = 4 = 11 - 6 - 1\).
Decrement (\(M=0\), \(S_1S_0 = 11\), \(C_{in} = 0\)). Now \(Y = 1111\), and \(11 + 15 = 26 = 11010\), giving \(F = 1010 = 10\) with \(C_{out} = 1\). Adding the four-bit pattern for \(-1\) has decremented \(A\), and again the discarded carry is the \(2^4\) of the two's complement identity.
Exclusive-OR (\(M=1\), \(S_1S_0 = 10\)). No adder is involved: bit by bit, \(1011 \oplus 0110 = 1101\). The carry output is not meaningful and must be ignored.
Two notes follow from the table. Several operations appear twice — transfer \(A\) at both \(S_1S_0C_{in} = 000\) and \(111\) — which is the normal price of a simple operand-select network. And the ALU produces no flags of its own: zero is a four-input NOR across \(F\), negative is \(F_3\) read as a sign bit, and overflow is the exclusive-OR of the carries into and out of the most significant stage, exactly as Chapter 3 defined it.
4 Carry Propagation Between ALU Slices
The four slices of the last section are joined by a ripple carry, and Chapter 16 showed what that costs: the most significant sum bit cannot settle until a carry has walked the whole length of the adder. Inside a single package this is tolerable and is usually solved by carry-look-ahead within the four bits. Between packages it becomes the dominant delay, because a sixteen- or thirty-two-bit word needs four or eight ALU packages in a row.
Put numbers on it. Take a package that needs \(t_g = 15\) ns to produce a carry from its operands, \(t_c = 10\) ns to pass a carry from its input to its output, and \(t_F = 15\) ns from its carry input to a settled output word. Chained end to end, \(N\) packages settle after
which is 50 ns for a sixteen-bit machine (\(N = 4\)) but 170 ns for a sixty-four-bit one (\(N = 16\)), because the middle term grows with the word length while nothing else does. A single look-ahead generator serving four packages replaces that middle term by one fixed delay, giving \(15 + 10 + 15 = 40\) ns for sixteen bits, and two levels of generator give \(15 + 10 + 10 + 15 = 50\) ns for sixty-four bits, 3.4 times faster than the ripple.
That is why every serious ALU package brings out two extra pins. Instead of only a carry output, it produces a group propagate \(P\) and a group generate \(G\) for the four bits it contains:
\(P\) says that a carry entering the group will reappear at its output, and \(G\) says that the group makes a carry of its own regardless of what enters it. These are the same definitions Chapter 16 used for a single bit, applied to a block of four — the look-ahead idea being applied a second time, one level up.
The 74182 look-ahead carry generator takes four such \(P, G\) pairs and a carry-in and produces the three intermediate group carries in two gate delays, along with its own \(P\) and \(G\) so that a third level can be added for a sixty-four-bit machine. The principle scales logarithmically: each level of look-ahead multiplies the word length by four and adds only a constant delay.
One warning about the boundary between the halves of the ALU. When \(M\) selects logic mode, the carry chain is disabled, so \(P\), \(G\) and \(C_{out}\) carry no useful information. A cascade of ALU packages must therefore have every package in the same mode, and control logic that ignores the carry outputs whenever \(M = 1\).
5 The 74181 as a Case Study
The 74181, introduced in 1970, was the first ALU on a single chip and remained the standard teaching example long after it stopped being used in new designs. It is worth studying because it is exactly the structure of Figure 20.1, generalised until the function-select network can produce every useful transformation of \(B\) rather than just four.
The package is a 24-pin part with four-bit operands \(A\) and \(B\), a four-bit select \(S_3S_2S_1S_0\), a mode input \(M\), a carry input \(\overline{C_n}\), and outputs \(F_3\ldots F_0\), \(\overline{C_{n+4}}\), \(\overline{P}\), \(\overline{G}\) and an open-collector \(A = B\). Sixteen select codes and the mode bit give sixteen logic functions and sixteen arithmetic ones, each of the latter appearing twice over the carry input.
A few rows, in the active-HIGH operand convention, show the pattern:
| \(S_3S_2S_1S_0\) | Logic function (\(M=1\)) | Arithmetic function (\(M=0\), no carry in) |
|---|---|---|
0000 | \(A'\) | \(A\) |
0110 | \(A \oplus B\) | \(A\) minus \(B\) minus 1 |
1001 | \((A \oplus B)'\) | \(A\) plus \(B\) |
1011 | \(A \cdot B\) | \(AB\) minus 1 |
1100 | logic 1 | \(A\) plus \(A\) (shift left) |
1111 | \(A\) | \(A\) minus 1 |
Three features of the data sheet regularly confuse students. The first is the active-low convention: the carry pins and the \(P\) and \(G\) outputs are active-low, so \(\overline{C_n} = 0\) means a carry is being applied. The second is that the part has two function tables, one for active-HIGH operands and one for active-LOW, and they list different operations against the same select codes; if the arithmetic in a laboratory exercise comes out consistently wrong, the wrong table is the usual reason. The third is that \(A = B\) is open-collector, so it needs a pull-up resistor and can be wire-ANDed across several packages to compare words wider than four bits — the wired-AND connection of Chapter 13. That output is only meaningful when the part is set to subtract, because equality is detected as an all-ones result of \(A\) minus \(B\) minus 1.
Modern devices no longer look like this: a processor synthesised from the kind of hardware description Chapter 30 introduces has its adder architecture chosen by a tool, and its operation set decided by an instruction decoder rather than by four select pins. The organisation, though, is unchanged — transform an operand, add, select a result.
6 Binary-to-Gray and Gray-to-Binary Converters
Chapter 4 introduced the reflected binary or Gray code, in which successive values differ in exactly one bit, so that a shaft encoder read during a transition can never give a wildly wrong value. Any system using such an encoder needs a converter, and the design follows the procedure of Chapters 7 and 8 exactly — truth table, map, minimal expression — but produces an answer so much simpler than the truth table looks that it is worth doing carefully.
| Decimal | Binary \(B_3B_2B_1B_0\) | Gray \(G_3G_2G_1G_0\) | Decimal | Binary | Gray |
|---|---|---|---|---|---|
| 0 | 0000 | 0000 | 8 | 1000 | 1100 |
| 1 | 0001 | 0001 | 9 | 1001 | 1101 |
| 2 | 0010 | 0011 | 10 | 1010 | 1111 |
| 3 | 0011 | 0010 | 11 | 1011 | 1110 |
| 4 | 0100 | 0110 | 12 | 1100 | 1010 |
| 5 | 0101 | 0111 | 13 | 1101 | 1011 |
| 6 | 0110 | 0101 | 14 | 1110 | 1001 |
| 7 | 0111 | 0100 | 15 | 1111 | 1000 |
Treat the table as four separate four-variable functions of \(B_3B_2B_1B_0\). The first, \(G_3\), is 1 for exactly the eight rows with \(B_3 = 1\), so its map is two full columns and \(G_3 = B_3\) with no gate at all. For \(G_2\), read down the column: it is 1 for decimals 4 to 11, that is for \(B_3B_2 = 01\) and \(B_3B_2 = 10\), and 0 for \(B_3B_2 = 00\) and \(11\). The map has two groups of four cells and gives
The two product terms are the definition of the exclusive-OR, so the minimal sum of products is a single XOR gate rather than two ANDs and an OR. \(G_1\) and \(G_0\) come out the same way with the variables shifted along, giving \(G_1 = B_2 \oplus B_1\) and \(G_0 = B_1 \oplus B_0\).
The general rule is therefore \(G_{n-1} = B_{n-1}\) and \(G_i = B_{i+1} \oplus B_i\): the most significant bit is copied and every other Gray bit is the exclusive-OR of two neighbouring binary bits. An \(n\)-bit converter is \(n-1\) XOR gates, all working simultaneously, so the conversion takes one gate delay however wide the word.
Reversing the conversion is not symmetrical, and the reason is instructive. Rearranging \(G_i = B_{i+1} \oplus B_i\) with the XOR property \(X \oplus X = 0\) gives \(B_i = B_{i+1} \oplus G_i\), which expresses each binary bit in terms of the Gray bit at the same position and the binary bit above it — a bit that has itself still to be computed. The conversion is therefore recursive: \(B_3 = G_3\), then \(B_2 = B_3 \oplus G_2\), then \(B_1 = B_2 \oplus G_1\), then \(B_0 = B_1 \oplus G_0\).
Substituting each equation into the next removes the recursion: \(B_i = G_{n-1} \oplus \cdots \oplus G_i\), the parity of all the Gray bits from the most significant down to that position. Built as parity trees the converter is fast but larger; built as the cascade of Figure 20.2 it is only \(n-1\) XOR gates but \(n-1\) gate delays deep. This is the same chain-versus-tree trade that carry-look-ahead resolves in the adder.
Convert binary 1011 to Gray. \(G_3 = B_3 = 1\); \(G_2 = B_3 \oplus B_2 = 1 \oplus 0 = 1\); \(G_1 = B_2 \oplus B_1 = 0 \oplus 1 = 1\); \(G_0 = B_1 \oplus B_0 = 1 \oplus 1 = 0\). The Gray code is 1110, which the table above confirms against decimal 11.
Now convert 1110 back. \(B_3 = G_3 = 1\); \(B_2 = B_3 \oplus G_2 = 1 \oplus 1 = 0\); \(B_1 = B_2 \oplus G_1 = 0 \oplus 1 = 1\); \(B_0 = B_1 \oplus G_0 = 1 \oplus 0 = 1\). The binary is 1011, as it must be. Note how the second calculation uses each answer to obtain the next, while the first used only the input bits.
7 BCD-to-Binary and Binary-to-BCD Conversion
Between binary and BCD there is no bitwise relationship to exploit, because ten is not a power of two. The two directions have to be treated as arithmetic rather than as coding, and they turn out to have quite different costs.
BCD to binary is the easy direction. A BCD number is a weighted sum, so a two-digit value \(D_1D_0\) is worth \(10D_1 + D_0\), and multiplying by ten in binary is free because \(10 = 8 + 2\):
A shift is a wiring pattern, not a circuit, so the whole converter is two binary adders. For three digits the hundreds contribute \(100D_2 = (D_2 \ll 6) + (D_2 \ll 5) + (D_2 \ll 2)\), since \(100 = 64 + 32 + 4\), and one more adder handles it.
0110 0111 to binaryThe digits are \(D_1 = 6\) and \(D_0 = 7\), so the number is 67. Shifting the pattern 0110 left by three places gives 0110000 (48), and shifting it left by one place gives 0001100 (12). Their sum is 0111100 (60), which is \(10 \times 6\) as expected. Adding \(D_0\), which is 0000111, gives 1000011.
Check: \(1000011_2 = 64 + 2 + 1 = 67\). The width is right too — two BCD digits span 0 to 99, which needs seven bits, and the converter's output is seven bits wide.
Binary to BCD has no such shortcut, because dividing by ten is not a shift. The standard method is the shift-and-add-3 algorithm, also called double dabble. Set up a register holding the binary number at the right-hand end and one four-bit field per decimal digit to its left, all initially zero. Then repeat, once for every bit of the binary number: inspect each BCD field, and if it holds 5 or more add 3 to it; then shift the whole register left by one place, so that the top bit of the binary number moves into the units field.
The add-3 rule looks arbitrary until you see what the shift is doing. A left shift doubles the value held in the BCD fields. A decimal digit \(d\) that is 5 or more will double to 10 or more, which no longer fits in one digit and must produce a carry into the next. Adding 3 first gives \(2(d+3) = 2d + 6\), and since \(2d + 6 \ge 16\) whenever \(d \ge 5\), the sixteen is a 1 shifted into the next digit while \(2d + 6 - 16 = 2d - 10\) is left behind — which is precisely the correct units result after the decimal carry. Adding 3 before doubling is the same correction as adding 6 after it, and Chapter 3 met that +6 as the BCD addition correction.
10101101 to BCDThe number is \(128 + 32 + 8 + 4 + 1 = 173\), so the answer should be 0001 0111 0011.
| Step | Hundreds | Tens | Units | Binary left |
|---|---|---|---|---|
| start | 0000 | 0000 | 0000 | 10101101 |
| shift 1 | 0000 | 0000 | 0001 | 0101101 |
| shift 2 | 0000 | 0000 | 0010 | 101101 |
| shift 3 | 0000 | 0000 | 0101 | 01101 |
| units ≥ 5, add 3 | 0000 | 0000 | 1000 | 01101 |
| shift 4 | 0000 | 0001 | 0000 | 1101 |
| shift 5 | 0000 | 0010 | 0001 | 101 |
| shift 6 | 0000 | 0100 | 0011 | 01 |
| shift 7 | 0000 | 1000 | 0110 | 1 |
| units ≥ 5, add 3 | 0000 | 1000 | 1001 | 1 |
| tens ≥ 5, add 3 | 0000 | 1011 | 1001 | 1 |
| shift 8 | 0001 | 0111 | 0011 | — |
After eight shifts the fields read 1, 7 and 3, so the answer is 0001 0111 0011, which is 173. Three corrections were needed in the whole conversion. Notice that no correction is applied after the final shift: the algorithm corrects only in preparation for a shift that is still to come, and a digit left holding 5 or more at the end is a perfectly valid BCD digit.
The algorithm becomes a circuit in either of two ways. As a sequential machine it is a shift register, an add-3 corrector per digit and a controller that counts the shifts — a natural use for the registers of Chapter 25. As a combinational circuit the loop is unrolled: each add-3 test becomes a small four-in, four-out block, the shifts become wiring, and an eight-bit converter is a triangular array of such blocks. The combinational version is fast and needs no clock; the sequential version is far smaller. Unrolling an algorithm in space or iterating it in time is a recurring decision in digital design, and it returns in the multiplier of Chapter 17 and the successive-approximation converter of Chapter 29.
8 Summary and Key Results
| Item | Statement | Consequence |
|---|---|---|
| Operand modification | \(Y \in \{0000,\,B,\,B',\,1111\}\) chosen by a 4-to-1 multiplexer per bit | One adder yields transfer, increment, add, subtract and decrement |
| Subtraction | \(A + B' + 1 = 2^n + (A-B)\), the \(2^n\) leaving as the carry out | \(C_{out} = 1\) means no borrow; \(C_{in} = 0\) gives \(A - B - 1\) |
| Mode input \(M\) | Selects logic instead of arithmetic and disables the carry chain | Carry, \(P\) and \(G\) are meaningless whenever \(M = 1\) |
| Cascading slices | Group \(P = p_3p_2p_1p_0\) and \(G = g_3 + p_3g_2 + p_3p_2g_1 + p_3p_2p_1g_0\) | A 74182 turns a 165 ns sixteen-bit ripple into about 50 ns |
| Binary to Gray | \(G_{n-1} = B_{n-1}\), \(G_i = B_{i+1} \oplus B_i\) | \(n-1\) XOR gates in parallel: one gate delay for any word length |
| Gray to binary | \(B_{n-1} = G_{n-1}\), \(B_i = B_{i+1} \oplus G_i\) — recursive | A cascade of \(n-1\) gate delays, or a parity tree if speed matters |
| BCD to binary | \(10D_1 + D_0 = (D_1 \ll 3) + (D_1 \ll 1) + D_0\) | Shifts are wiring, so the converter is just binary adders |
| Binary to BCD | Shift-and-add-3: correct every digit holding \(\ge 5\), then shift left | \(2(d+3) = (2d-10) + 16\), so the 3 becomes the decimal carry |
9 Common Mistakes
Applying \(B'\) to the adder implements \(A + B' = A - B - 1\), not \(A - B\). The missing 1 is supplied by the carry input, which is why every ALU function table lists subtraction with \(C_{in} = 1\). The symptom is an answer that is consistently one too small, which is easy to mistake for an off-by-one in the test bench rather than a wrongly tied pin.
In logic mode the adder is bypassed and, in a real part, its internal carries are disabled by the mode input. Whatever appears on \(C_{out}\), \(\overline{P}\) and \(\overline{G}\) then has no arithmetic meaning. Control logic must gate these signals with \(M\), and a cascade of packages must be put in the same mode throughout — a half-arithmetic, half-logic cascade produces nonsense in the middle of the word.
The correction exists to prepare a digit for doubling, so it must be applied to the digit as it stands and only then may the register be shifted. Testing after the shift corrects a digit that has already overflowed, and the conversion drifts away from the right answer within two or three steps. The other half of the same mistake is correcting once more after the final shift: the last shift is not followed by another doubling, so a digit holding 5 or more at that point is simply the answer.
10 Chapter Review
1. Show algebraically that an adder fed with \(B'\) and a carry-in of 1 subtracts, and use it to compute \(1001 - 0110\) on a four-bit ALU. State what the carry output means.
The two's complement of a four-bit word \(B\) is \(2^4 - B\) and is formed as \(B' + 1\). Hence \(A + B' + 1 = A + (2^4 - B) = 2^4 + (A - B)\). The \(2^4\) is a fifth bit, which leaves the four-bit output as the carry, so the sum bits hold \(A - B\). Numerically, \(A = 1001 = 9\) and \(B = 0110 = 6\), so \(B' = 1001 = 9\) and the adder forms \(9 + 9 + 1 = 19 = 10011\). The output word is \(0011 = 3\), which is \(9 - 6\), and \(C_{out} = 1\). The carry being 1 signals that the \(2^4\) term appeared, that is, that no borrow was needed and \(A \ge B\). Had \(A\) been smaller than \(B\) the carry would have been 0 and the result would have been the two's complement of the magnitude of the difference.
2. Using the function table of Section 3, give the control word for incrementing \(A\) and for forming \(A \oplus B\), and evaluate both for \(A = 1001\), \(B = 0110\).
Incrementing \(A\) is an arithmetic operation with the operand multiplexers passing \(Y = 0000\) and the carry input supplying the 1, so \(M = 0\), \(S_1S_0 = 00\), \(C_{in} = 1\). For \(A = 1001 = 9\) the adder forms \(9 + 0 + 1 = 10\), giving \(F = 1010\) with \(C_{out} = 0\). The exclusive-OR is a logic operation, so \(M = 1\), \(S_1S_0 = 10\), and the carry input is irrelevant. Bit by bit, \(1001 \oplus 0110 = 1111\), and the carry output must be ignored. Note that the same select code \(S_1S_0 = 10\) means subtract when \(M = 0\) and exclusive-OR when \(M = 1\); the select lines choose a column of the table and the mode bit chooses which table.
3. A sixteen-bit ALU is built from four four-bit packages, each needing 15 ns to make a carry from its operands, 10 ns from carry in to carry out and 15 ns from carry in to a settled output word. Compare the worst-case delay of a ripple connection with a look-ahead connection, and say where the group \(P\) and \(G\) signals come from.
Rippling, the first package makes a carry from its operands in \(t_g = 15\) ns, that carry crosses the two middle packages in \(2 \times 10 = 20\) ns, and the last package settles \(t_F = 15\) ns after receiving it: \(t = 15 + 20 + 15 = 50\) ns. With a 74182 the four packages present their group signals after 15 ns, the generator produces all three intermediate carries 10 ns later, and the outputs settle 15 ns after that, giving 40 ns. The gain is modest at sixteen bits because only two carry hops were removed, but the ripple time grows as \(t_g + (N-2)t_c + t_F\) while the look-ahead time does not, so at sixty-four bits (\(N = 16\)) the two figures are 170 ns and 50 ns. The group signals come from inside each ALU package: \(P = p_3p_2p_1p_0\) is the AND of the four bit-propagate terms and says a carry entering the group will leave it, while \(G = g_3 + p_3g_2 + p_3p_2g_1 + p_3p_2p_1g_0\) says the group makes a carry of its own. They are the Chapter 16 definitions applied to a block of four bits rather than to one.
4. Derive the Gray code for binary \(1101\) and convert Gray \(1011\) back to binary. Why is the second conversion slower in gate delays?
For binary to Gray, \(G_3 = B_3 = 1\), \(G_2 = B_3 \oplus B_2 = 1 \oplus 1 = 0\), \(G_1 = B_2 \oplus B_1 = 1 \oplus 0 = 1\) and \(G_0 = B_1 \oplus B_0 = 0 \oplus 1 = 1\), giving
1011. For Gray to binary, \(B_3 = G_3 = 1\), \(B_2 = B_3 \oplus G_2 = 1 \oplus 0 = 1\), \(B_1 = B_2 \oplus G_1 = 1 \oplus 1 = 0\) and \(B_0 = B_1 \oplus G_0 = 0 \oplus 1 = 1\), giving1101— the original number, as it must be. The forward conversion is slower in no respect: each of its three XOR gates takes only input bits, so all three settle in one gate delay. The reverse conversion feeds each result into the next gate, so the chain is three gate delays deep for four bits and \(n-1\) deep in general. The recursion can be flattened by writing \(B_i = G_3 \oplus G_2 \oplus \cdots \oplus G_i\), which is a parity tree of logarithmic depth but uses more gates.5. Convert binary \(11001\) to BCD using shift-and-add-3, showing every step, and state how many corrections were needed.
The number is \(16 + 8 + 1 = 25\), so two BCD digits suffice. Starting with tens and units both
0000and the binary11001to the right: after shift 1 the units hold0001; after shift 2,0011; after shift 3,0110. The units now hold 6, which is 5 or more, so add 3 to get1001. Shift 4 moves the 1 out of the units into the tens, leaving tens0001and units0010. Shift 5 brings in the last binary bit, giving tens0010and units0101. The result is0010 0101, which is 25. Exactly one correction was needed. The units field ends holding 5, but no correction is applied to it because no further shift follows.