|
But there is another way to perform subtraction with fixed length binary numbers !!!
In CS255, we have learn this method to find the 2s complement representation for −x:
x = 00000011 (repr: 3 decimal) (1) flip all bits: 11111100 (2) add 1 11111101 (repr: -3 decimal) |
Because: a − x ≡ a + (−x), we can use the full adder circuit to construct a subtractor circuit !!!
We start with the 4 bits addition circuit:
Note: a − b ≡ a + (−b)
And: − b ≡ (1) flip the bits in b and (2) add 1
(1) Flip all bits in the binary number "b":
Note: a − b ≡ a + (−b)
And: − b ≡ (1) flip the bits in b and (2) add 1
(2) Add 1 (we can use the carry input of the first full adder):
Note: a − b ≡ a + (−b)
And: − b ≡ (1) flip the bits in b and (2) add 1
We must also adjust the carry output...
It turns out that negating cout will give us the correct signal for borrow (no explanation to save time)
DEMO: /home/cs355001/demo/circuits/4-bit-subtract