Subtraction Is Addition
In Section 2.1, we designed high-speed binary adders. This article begins the design of an Arithmetic Logic Unit (ALU) by implementing binary subtraction. Digital hardware does not require a separate subtraction circuit. By exploiting the mathematical properties of two’s complement representation, a standard binary adder performs both addition and subtraction. The modification requires only a layer of XOR gates and a controlled carry-in line.
Two’s Complement Subtraction Mathematical Identity
In two’s complement arithmetic, the negative value of operand $B$ equals its bitwise complement ($\overline{B}$) plus one:
$$-B = \overline{B} + 1$$
Therefore, subtracting $B$ from $A$ equals adding the two’s complement of $B$ to $A$:
$$A - B = A + (-B) = A + \overline{B} + 1$$
This identity defines two hardware operations:
- Invert every bit of operand $B$ to generate $\overline{B}$.
- Assert logic 1 on the adder carry-in line ($C_{\text{in}} = 1$) to add the required $+1$.
Because standard adder architectures already provide a carry-in port on the least significant bit, adding 1 requires zero additional adder cells.
XOR Gate as a Controlled Bitwise Inverter
An XOR gate functions as a controlled bitwise inverter.
Table 1 shows the behavior when control signal sub drives one input:
sub |
$B$ | Output ($B \oplus \text{sub}$) | Operation |
|---|---|---|---|
| 0 | 0 | 0 | Pass true value ($B$) |
| 0 | 1 | 1 | Pass true value ($B$) |
| 1 | 0 | 1 | Invert value ($\overline{B}$) |
| 1 | 1 | 0 | Invert value ($\overline{B}$) |
When sub = 0, the output equals $B$.
When sub = 1, the output equals $\overline{B}$.
Unified Adder/Subtractor Architecture
Figure 1 illustrates a 4-bit unified adder/subtractor circuit:
The circuit operates in two distinct modes controlled by the sub signal:
- Addition Mode (
sub= 0): The XOR gates pass operand $B$ without inversion. The base carry-in is $C_0 = 0$. The adder computes $A + B + 0 = A + B$. - Subtraction Mode (
sub= 1): The XOR gates invert operand $B$ into $\overline{B}$. The base carry-in is $C_0 = 1$. The adder computes $A + \overline{B} + 1 = A - B$.
Numerical Walkthrough: Positive Result ($6 - 3$)
Evaluate $A - B$ for $A = 0110_2$ ($+6_{10}$) and $B = 0011_2$ ($+3_{10}$).
Set sub = 1:
- Invert $B$: $\overline{B} = 1100_2$.
- Assert initial carry: $C_0 = 1$.
Table 2 traces the addition of $A + \overline{B} + 1$:
| Bit ($i$) | $A_i$ | $\overline{B_i}$ | $C_i$ | Sum Bit ($S_i$) | Carry-Out ($C_{i+1}$) |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 | 1 | 0 |
| 2 | 1 | 1 | 0 | 0 | 1 |
| 3 | 0 | 1 | 1 | 0 | 1 |
Result: $S = 0011_2$ ($+3_{10}$), with carry-out $C_4 = 1$. The result is correct.
Numerical Walkthrough: Negative Result ($3 - 6$)
Evaluate $A - B$ for $A = 0011_2$ ($+3_{10}$) and $B = 0110_2$ ($+6_{10}$).
Set sub = 1:
- Invert $B$: $\overline{B} = 1001_2$.
- Assert initial carry: $C_0 = 1$.
Table 3 traces the bitwise evaluation:
| Bit ($i$) | $A_i$ | $\overline{B_i}$ | $C_i$ | Sum Bit ($S_i$) | Carry-Out ($C_{i+1}$) |
|---|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 0 | 1 |
| 2 | 0 | 0 | 1 | 1 | 0 |
| 3 | 0 | 1 | 0 | 1 | 0 |
Result: $S = 1101_2$ with carry-out $C_4 = 0$. The MSB is 1, indicating a negative signed result. In 4-bit two’s complement:
$$1101_2 = -8 + 4 + 1 = -3_{10}$$
The result is correct ($3 - 6 = -3$).
Signed Overflow Detection Logic ($V$)
Signed arithmetic overflow occurs when the true mathematical result exceeds the representable range of an $N$-bit signed word ($-2^{N-1}$ to $+2^{N-1} - 1$). For both addition and subtraction, compare the carry entering the most significant full adder ($C_{N-1}$) with the carry leaving it ($C_N$):
$$V = C_{N-1} \oplus C_N$$
Table 4 lists the overflow evaluation rules:
| $C_{N-1}$ (Carry In to MSB) | $C_N$ (Carry Out of MSB) | Overflow Flag ($V$) | Interpretation |
|---|---|---|---|
| 0 | 0 | 0 | Valid result; no overflow occurred. |
| 0 | 1 | 1 | Overflow occurred; result exceeded positive limit. |
| 1 | 0 | 1 | Underflow occurred; result exceeded negative limit. |
| 1 | 1 | 0 | Valid result; no overflow occurred. |
Unsigned Borrow Detection Logic
In unsigned subtraction, the system must detect whether operand $A$ is strictly less than operand $B$ ($A < B$), requiring an arithmetic borrow. The adder carry-out ($C_{\text{out}} = C_N$) indicates borrow status in inverted form:
$$\text{Borrow} = \overline{C_{\text{out}}}$$
- When $A \ge B$: The addition $A + \overline{B} + 1$ produces $C_{\text{out}} = 1$. Therefore, $\text{Borrow} = 0$.
- When $A < B$: The addition fails to generate a final carry ($C_{\text{out}} = 0$). Therefore, $\text{Borrow} = 1$.
In Example 1 ($6 \ge 3$), $C_{\text{out}} = 1 \implies \text{Borrow} = 0$.
In Example 2 ($3 < 6$), $C_{\text{out}} = 0 \implies \text{Borrow} = 1$.
Microprocessors use this inverted carry convention to drive conditional branch instructions (BHS / BLO).
Circuit Propagation Delay Analysis
The XOR gating layer introduces a single gate delay on operand $B$:
- Operand $B$ to XOR output: 1 gate delay.
- Carry ripple through $N$ full adders: $2N$ gate delays.
- Final sum bit generation: 1 gate delay.
- Total worst-case latency: $2N + 2$ gate delays.
The unified adder/subtractor doubles operational functionality with minimal silicon area and negligible latency overhead.
Practice Exercises
Problem 1: Compute $A - B$ using the 4-bit adder/subtractor for signed operands $A = 0101_2$ ($+5_{10}$) and $B = 1010_2$ ($-6_{10}$). Determine the 4-bit sum, the final carry-out, and the overflow flag $V$.
View Solution
Operand inversion:
- $B = 1010_2 \implies \overline{B} = 0101_2$.
- Carry-in $C_0 = 1$.
Trace bitwise addition ($A + \overline{B} + C_0 = 0101 + 0101 + 1$):
- Bit 0: $1 + 1 + 1 \implies S_0 = 1, C_1 = 1$.
- Bit 1: $0 + 0 + 1 \implies S_1 = 1, C_2 = 0$.
- Bit 2: $1 + 1 + 0 \implies S_2 = 0, C_3 = 1$.
- Bit 3: $0 + 0 + 1 \implies S_3 = 1, C_4 = 0$.
Outputs:
- Sum output: $S = 1011_2$.
- Final carry: $C_{\text{out}} = C_4 = 0$.
- Overflow evaluation: $V = C_3 \oplus C_4 = 1 \oplus 0 = 1$.
Analysis: The true arithmetic result is $5 - (-6) = +11_{10}$. The maximum representable 4-bit signed integer is $+7_{10}$. Because $+11 > +7$, signed overflow occurred ($V = 1$). The sum bits $1011_2$ represent $-5_{10}$, which is invalid. The overflow flag warns downstream logic of the arithmetic error.
Problem 2: Compute unsigned subtraction $A - B$ for $A = 0010_2$ ($2_{10}$) and $B = 0111_2$ ($7_{10}$). Determine the sum, final carry-out, and unsigned borrow status.
View Solution
Operand inversion:
- $\overline{B} = 1000_2$.
- Carry-in $C_0 = 1$.
Perform addition ($0010_2 + 1000_2 + 1_2$):
- $0010 + 1000 + 1 = 1011_2$.
- Carry-out: $C_{\text{out}} = 0$.
- Borrow evaluation: $\text{Borrow} = \overline{C_{\text{out}}} = \overline{0} = 1$.
Because $2 < 7$, an unsigned borrow occurred. The output bits $1011_2$ represent $11_{10} = (2 - 7 + 16)$, which is the modulo-$2^4$ wrapped difference.
In the next article, we build an integrated adder/subtractor module with complete status flag generation.