Sub topic 2
Half adders, full adders and subtractors
This chapter assumes you know binary numbers, the AND, OR, XOR and NOT gates, and Boolean expressions. It covers arithmetic blocks, selection and encoding circuits, ROM/PLA/PAL, static hazards, and flip-flop tables.
Half and full adders
A half adder adds two bits. Its sum is a XOR b and its carry is a AND b.
A full adder adds three bits: a, b, and carry-in cin. Its sum is a XOR b XOR cin, and its carry-out is (a AND b) OR (cin AND (a XOR b)).
A full subtractor computes a - b - bin using the same XOR structure, with a borrow output in place of a carry.
module full_adder(input a, input b, input cin, output sum, output cout);
assign sum = a ^ b ^ cin;
assign cout = (a & b) | (cin & (a ^ b));
endmoduleRipple-carry versus carry-lookahead
A ripple-carry adder chains full adders. Each carry waits for the previous stage, so delay grows with word width.
A carry-lookahead adder computes each carry directly from generate (g = a AND b) and propagate (p = a XOR b) signals. It is faster for wide words but uses more gates.
Multiplexers, decoders and encoders
A multiplexer (MUX) selects one of several inputs using select lines. A 4-to-1 MUX needs two select lines. Any Boolean function of n variables can be built from a 2^(n-1)-to-1 MUX.
A decoder turns an n-bit code into one of 2^n active outputs. An encoder does the reverse. A priority encoder gives the highest-numbered active input priority.
ROM, PLA and PAL
A ROM (read-only memory) stores a full truth table: the address selects a row. A PLA (programmable logic array) has a programmable AND plane and OR plane. A PAL (programmable array logic) fixes the OR plane and programs only the AND plane.
Static hazards
A static hazard is a brief glitch on an output that should stay constant. In F = AB + B'C, with A = C = 1, switching B can glitch F to 0. Adding the consensus term AC removes the glitch.
> Note: Adding the consensus term removes the hazard but adds a gate. This is a trade-off, not a free fix.
Latches and flip-flops
A D flip-flop has characteristic equation Q+ = D. A T flip-flop has Q+ = T XOR Q. A JK flip-flop has Q+ = JQ' + K'Q.
The excitation table gives the inputs needed for a state change. For a JK flip-flop:
| Q | Q+ | J | K |
|---|---|---|---|
| 0 | 0 | 0 | X |
| 0 | 1 | 1 | X |
| 1 | 0 | X | 1 |
| 1 | 1 | X | 0 |
Exercise
What carry-out does a full adder produce when a = 1, b = 1, cin = 0?
Show answer
1. The carry is (a AND b) OR (cin AND (a XOR b)) = 1 OR 0 = 1.