A minus B, with a borrow bit for when you run out of room. A ready-made arithmetic circuit you can open in the TorchAnvil simulator.
Subtraction looks a lot like addition at the bit level. 0 - 0 = 0,
1 - 0 = 1, 1 - 1 = 0 — easy. The awkward one is 0 - 1: you can't
do it without reaching into the next column for help. That's a borrow,
and a half subtractor catches it on a dedicated output.
Two gates, two outputs:
A XOR B. This is the same XOR the half adder uses for
its Sum — a reminder that add and subtract are the same operation
until the carry/borrow enters the picture.(NOT A) AND B. It fires in exactly one case: when A = 0
and B = 1. That's the 0 - 1 column where you have to reach one
column to the left and bring a 1 back down.| A | B | Diff | Borrow |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
Chain a half subtractor with a full subtractor (accepts a borrow in as well as producing one out) and you have the subtraction equivalent of a ripple-carry adder. Most real CPUs don't bother, though — they reuse the adder by flipping B's bits and adding 1, the "two's complement" trick. Still, it's worth seeing subtraction built from first principles.
0 - 1
and the Borrow lamp is the circuit telling you "I owe you one."1 - 0 = 1.1 - 1 = 0, nothing borrowed.