An adder/subtractor is one circuit that can add or subtract, chosen by a single mode line M. It's built from:
- a ripple carry adder
- a controlled inverter (an XOR gate) on every B input, all driven by M
- the same M wired to the carry-in C0
When M = 0, the XORs pass B unchanged and C0 = 0, so the output is A + B.
When M = 1, the XORs invert B and C0 = 1, so the output is A + + 1. In twos complement, + 1 is −B, so that's A − B (twos complement subtraction).
The neat part is that the +1 costs nothing: the adder already has a carry-in, and M simply drives it. An n-bit adder/subtractor needs only n extra XOR gates.
Reading the results:
- Unsigned: after an add, a carry out of 1 means overflow. After a subtract, carry-out 1 means no borrow (A ≥ B).
- Signed: V = Cₙ ⊕ Cₙ₋₁ detects signed overflow for both operations, because it looks at what the adder really adds.
Since bit 0 receives C0 = M, it needs a full adder, not a half adder.