Module 2: Combinational Circuit Design · 2.2 Subtractors & ALU Design

Building a 4-Bit ALU

In the previous article, we established the parallel compute-and-select architecture of an Arithmetic Logic Unit (ALU). This article implements a fully functional 4-bit ALU with eight operations. We design each sub-block at the gate level, specify signal routing, estimate total gate counts, and analyze critical path timing.

Functional Specification and Opcode Assignment

The 4-bit ALU receives two 4-bit data operands ($A[3:0], B[3:0]$) and a 3-bit operation code (opcode[2:0] or $S_2 S_1 S_0$). It produces a 4-bit output vector $R[3:0]$ and four status flags ($Z, N, C, V$). Table 1 specifies the operation mapping:

Opcode ($S_2 S_1 S_0$) Operation Identifier Mathematical / Logical Expression Description
000 ADD $A + B$ 4-bit unsigned/signed binary addition
001 SUB $A - B$ 4-bit two’s complement subtraction ($A + \overline{B} + 1$)
010 AND $A \ & \ B$ Bitwise logical AND
011 OR $A \ | \ B$ Bitwise logical OR
100 XOR $A \oplus B$ Bitwise logical XOR
101 NOT $\overline{A}$ Bitwise inversion (operand $B$ ignored)
110 PASSA $A$ Register pass-through of operand $A$
111 PASSB $B$ Register pass-through of operand $B$

Step 1: Arithmetic Sub-Unit Design

The arithmetic sub-unit executes both addition and subtraction. Because ADD is encoded as 000 and SUB as 001, bit $S_0$ directly controls the subtraction mode:

  • Four XOR gates compute $B’_i = B_i \oplus S_0$.
  • Carry-in $C_0$ connects to $S_0$.
  • A 4-bit ripple-carry adder (FA0 through FA3) sums $A$ and $B’$.

The unit generates:

  • 4-bit arithmetic sum: $S_{\text{arith}}[3:0]$.
  • Final carry-out of FA3: $\text{ArithCout}$ ($c_4$).
  • Intermediate carry entering FA3: $c_3$.

Hardware cost: 4 XOR gates + 4 full adders ($\approx 20$ gates) $= 24$ logic gates.

Step 2: Bitwise Logic Sub-Unit Design

The logic sub-unit executes four bitwise operations in parallel across all four bit positions:

  • Bitwise AND: $A_i \cdot B_i$ (4 AND gates).
  • Bitwise OR: $A_i + B_i$ (4 OR gates).
  • Bitwise XOR: $A_i \oplus B_i$ (4 XOR gates).
  • Bitwise NOT: $\overline{A_i}$ (4 inverters).

Hardware cost: 16 logic gates. Each logic output evaluates in a single gate delay.

Step 3: 4-Bit 8-to-1 Output Multiplexer

A 4-bit-wide 8-to-1 multiplexer selects the final output bus $R[3:0]$ based on opcode[2:0] (Table 2):

MUX Port Index Connected Input Bus Selected Opcode ($S_2 S_1 S_0$)
0 Arithmetic Sum ($A + B$) 000
1 Arithmetic Sum ($A - B$) 001
2 Bitwise AND 010
3 Bitwise OR 011
4 Bitwise XOR 100
5 Bitwise NOT 101
6 Operand $A$ (PASSA) 110
7 Operand $B$ (PASSB) 111

Ports 0 and 1 share the arithmetic result bus because the adder/subtractor automatically produces the correct sum or difference based on $S_0$. Implementing a 4-bit 8-to-1 multiplexer using a 3-level tree of 2-to-1 multiplexers requires approximately 80 gate equivalents and introduces three gate delays.

Step 4: Status Flag Generation Logic

Condition flags report the execution status:

  1. Zero Flag ($Z$): $$Z = \overline{R_3 + R_2 + R_1 + R_0}$$ Uses a 4-input NOR tree on the final multiplexer output (two gate delays).
  2. Negative Flag ($N$): $$N = R_3$$ Connects directly to MSB output bit $R_3$ (zero gate delays).
  3. Carry Flag ($C$): $$C = \text{ArithCout}$$ Connects to carry-out $c_4$ of the arithmetic sub-unit.
  4. Overflow Flag ($V$): $$V = c_3 \oplus \text{ArithCout}$$ Uses one 2-input XOR gate to compare carries around the most significant full adder.

Total flag hardware cost: 5 logic gates.

Integrated Circuit Schematic

Figure 1 illustrates the complete gate-level schematic of the 4-bit ALU:

Complete ALU
Figure 1: Gate-level schematic of the complete 4-bit Arithmetic Logic Unit

Execution Trace: Subtraction ($7 - 3$)

We trace subtraction: $A = 0111_2$ ($+7$), $B = 0011_2$ ($+3$), opcode = 001 ($S_0 = 1$).

  1. XOR Input Gating: $S_0 = 1 \implies B’ = 1100_2$, with carry-in $C_0 = 1$.
  2. Arithmetic Addition: The adder computes $0111_2 + 1100_2 + 1_2$:
    • Bit 0: $1 + 0 + 1 \implies S_0 = 0, C_1 = 1$.
    • Bit 1: $1 + 0 + 1 \implies S_1 = 0, C_2 = 1$.
    • Bit 2: $1 + 1 + 1 \implies S_2 = 1, C_3 = 1$.
    • Bit 3: $0 + 1 + 1 \implies S_3 = 0, C_4 = 1$.
    • Arithmetic output $= 0100_2$, $c_3 = 1, \text{ArithCout} = 1$.
  3. Logic Sub-Unit Execution:
    • $\text{AND} = 0011_2$, $\text{OR} = 0111_2$, $\text{XOR} = 0100_2$, $\text{NOT} = 1000_2$.
  4. Multiplexer Routing: Opcode 001 selects Port 1: $R = 0100_2$ ($+4_{10}$).
  5. Flag Evaluation:
    • $Z = \overline{0 + 1 + 0 + 0} = 0$.
    • $N = R_3 = 0$.
    • $C = \text{ArithCout} = 1$ (no unsigned borrow occurred).
    • $V = c_3 \oplus \text{ArithCout} = 1 \oplus 1 = 0$ (no signed overflow).

Result: $R = 4_{10}$, with flags $Z = 0, N = 0, C = 1, V = 0$. The computation is verified.

Gate Count and Silicon Area Budget

Table 3 summarizes the logic gate requirements of the 4-bit ALU:

Functional Block Component Types Equivalent Logic Gate Count Percentage of Total Area
Arithmetic Unit 4 XOR gates, 4 Full Adders 24 19.2%
Logic Unit 4 AND, 4 OR, 4 XOR, 4 NOT 16 12.8%
Output Multiplexer 4-bit 8-to-1 multiplexer tree 80 64.0%
Status Flags 4-input NOR tree, 1 XOR 5 4.0%
Total ALU Hardware - 125 gates 100.0%

The 8-to-1 output multiplexer consumes 64% of total silicon area.

Critical Path Propagation Delay Analysis

Table 4 compares propagation delays across different functional paths:

Functional Path Detailed Gate Sequence Total Delay
Operand $A/B \to$ Logic Unit Output 1 logic gate 1 gate delay
Operand $B \to$ Arithmetic Carry Chain 1 XOR gate $+$ 4 Full Adders ($2 \times 4$) 9 gate delays
Carry Chain $\to$ Overflow Flag ($V$) 9 carry delays $+$ 1 XOR gate 10 gate delays
Carry Chain $\to$ Output Multiplexer $\to$ Zero Flag ($Z$) 9 carry delays $+$ 1 Sum XOR $+$ 3 MUX $+$ 2 NOR 15 gate delays
Logic Unit $\to$ Output Multiplexer $\to$ Zero Flag ($Z$) 1 Logic gate $+$ 3 MUX $+$ 2 NOR 6 gate delays

The arithmetic path to the Zero flag ($Z$) represents the worst-case critical timing path (15 gate delays). Replacing the ripple-carry chain with a carry-lookahead adder reduces this critical path from 15 to 11 gate delays.

Practice Exercises

Problem 1: Trace operation opcode = 010 (Bitwise AND) for input operands $A = 1011_2$ and $B = 0110_2$. Determine output vector $R[3:0]$ and condition flags $Z, N, C, V$.

View Solution
  1. Functional Evaluation:
    • The logic unit computes bitwise AND: $$R = A \ & \ B = 1011_2 \ & \ 0110_2 = 0010_2$$
    • The multiplexer routes Port 2 to output $R$: $R = 0010_2$.
  2. Flag Evaluation:
    • $Z = \overline{0 + 0 + 1 + 0} = 0$ (non-zero result).
    • $N = R_3 = 0$ (positive MSB).
    • Flags $C$ and $V$ reflect unselected arithmetic adder outputs ($c_4 = 1, V = 1$). Standard processor instruction set architectures treat flags $C$ and $V$ as undefined or unaffected during logical operations.

Problem 2: Calculate the worst-case propagation delay from input bus $B$ to status flag $V$, and identify all logic gates along this path.

View Solution

Signal path from operand $B$ to overflow flag $V$:

  1. XOR gating layer on $B$: 1 gate delay.
  2. Carry ripple across FA0, FA1, FA2, FA3: $4 \times 2 = 8$ gate delays.
  3. Overflow flag XOR gate ($V = c_3 \oplus c_4$): 1 gate delay.

Total propagation delay: $$t_{\text{delay}} = 1 + 8 + 1 = 10 \text{ gate delays}$$

Carry-in $c_3$ arrives at time $t = 7$. Because final carry $c_4$ arrives at time $t = 9$, signal $c_4$ determines the critical path timing.

In the next article, we examine how microprocessor instruction set architectures evaluate status flags to execute conditional branching.

← What an ALU Is The ALU Flags →