About

4.4 Combinational Circuits: Adders, Decoders, Multiplexers & ALU

Theory: Combinational Circuits: Adders, Decoders, Multiplexers & ALU

So far we have treated Boolean functions on paper. Now we build them. A combinational circuit is a network of gates whose outputs depend only on the current inputs: apply new inputs and, after a tiny gate delay, the outputs settle to the new values. There is no memory. Combinational circuits are the “doing” part of a CPU: adders, comparators, decoders, multiplexers and the ALU (Null & Lobur, Ch. 3).

From Boolean Function to Gate Circuit

Every Boolean expression maps directly onto gates:

Expression partGate
each complemented variable x′x'a NOT gate (inverter) on xx
each product terman AND gate with one input per literal
the sum of the termsan OR gate with one input per term

Procedure (two-level AND-OR circuit from a sum of products):

  1. Draw an inverter for each variable that appears complemented.
  2. Draw one AND gate per product term (a single-literal term needs no AND).
  3. Feed all product outputs into one OR gate; its output is FF.

Because every gate costs area, power and delay, we simplify first (identities or a K-map) and then draw the circuit.

Mini-example (lecture)

F(x,y,z)=x+y′zF(x, y, z) = x + y'z: one inverter makes y′y'; one AND gate computes y′zy'z; one OR gate combines xx with y′zy'z. Three gates in total.

F = x + y'zxyzy'y'zF

Half Adder

The simplest arithmetic circuit adds two bits xx and yy. The result can be 00, 11 or 2=1022 = 10_2, so it needs two outputs: Sum and Carry.

xxyyCarrySum
0000
0101
1001
1110

Reading the columns: Sum is 1 when the inputs differ → XOR; Carry is 1 only when both are 1 → AND.

Sum=x⊕y,Carry=xy\text{Sum} = x \oplus y, \qquad \text{Carry} = xy

So a half adder is just one XOR gate and one AND gate sharing the same two inputs.

Mini-example

1+11 + 1: Sum =1⊕1=0= 1 \oplus 1 = 0, Carry =1⋅1=1= 1 \cdot 1 = 1, i.e. 102=210_2 = 2 ✓.

Full Adder

To add multi-bit numbers, every column except the rightmost must also add the carry coming in from the column to its right. A full adder adds three bits: xx, yy and Carry In (zz, or CinC_{in}).

xxyyCinC_{in}Carry OutSum
00000
00101
01001
01110
10001
10110
11010
11111

As derived in 4.2:

Sum=x⊕y⊕Cin,Cout=xy+Cin(x⊕y)\text{Sum} = x \oplus y \oplus C_{in}, \qquad C_{out} = xy + C_{in}(x \oplus y)

Construction (the lecture’s circuit) = two half adders plus an OR gate:

Full adderxyCinx⊕yxyCin(x⊕y)SumCarry out

Intuition for the carry: a carry goes out if xx and yy are both 1 (generate, xyxy), or if exactly one of them is 1 and a carry comes in (propagate, Cin(x⊕y)C_{in}(x \oplus y)).

Ripple-Carry Adder

Chain nn full adders, one per bit column, connecting each Carry Out to the next column’s Carry In. The rightmost column has no incoming carry, so its Cin=0C_{in} = 0 (or a half adder is used there). The carry “ripples” from right to left, hence ripple-carry adder.

4-bit ripple-carry adderABCinSCoutFAABCinSCoutFAABCinSCoutFAABCinSCoutFAA0B00A1B1A2B2A3B3S0S1S2S3C4

The ripple-carry adder is simple but slow for wide words: bit n−1n-1 cannot produce its final sum until the carry has passed through all n−1n - 1 adders before it. Faster designs (carry-lookahead, carry-select) compute carries in parallel.

Decoder

A decoder takes an nn-bit binary number on its inputs and activates exactly one of its 2n2^n output lines: the one whose index equals the input value.

n inputs  ⟶  2n outputsn \text{ inputs} \;\longrightarrow\; 2^n \text{ outputs}

Main use: memory address decoding. The binary address placed on the address lines of a memory bus goes into a decoder, and the single active output selects (enables) one memory location or one memory chip. Address decoders with nn inputs can select any of 2n2^n locations.

Inside a 2-to-4 decoder: two inverters make x′x' and y′y', and four AND gates each produce one minterm:

xxyyx′y′x'y' (out 0)x′yx'y (out 1)xy′xy' (out 2)xyxy (out 3)
001000
010100
100010
110001

A decoder therefore generates all minterms of its inputs, which means any function can be built from a decoder plus one OR gate (Worked Example 6).

Mini-example (lecture)

In the 2-to-4 decoder, if x=0x = 0 and y=1y = 1, only the AND gate computing x′yx'y has both inputs at 1, so the x′yx'y output (output 1) is enabled.

Multiplexer (MUX)

A multiplexer does roughly the opposite of a decoder: it has many data input lines and one output, and the value on its control (select) lines chooses which input is passed to the output. Think of it as a digitally controlled rotary switch.

With ss select lines you can name 2s2^s inputs, so to select among nn inputs you need

s=log⁡2n control liness = \log_2 n \text{ control lines}

(From n=2sn = 2^s: log⁡n=slog⁡2\log n = s \log 2, so s=log⁡n/log⁡2=log⁡2ns = \log n / \log 2 = \log_2 n.)

Inside a 4-to-1 mux (inputs I0..I3I_0..I_3, selects S1S0S_1 S_0): two inverters, four 3-input AND gates and one 4-input OR gate:

Output=S1′S0′I0+S1′S0I1+S1S0′I2+S1S0I3\text{Output} = S_1'S_0'I_0 + S_1'S_0I_1 + S_1S_0'I_2 + S_1S_0I_3

For any select value, exactly one AND gate has both of its select inputs at 1, so it passes its data input; the other three output 0, and the OR gate forwards the chosen bit.

S1S_1S0S_0Output
00I0I_0
01I1I_1
10I2I_2
11I3I_3

Mini-example (lecture)

If S0=1S_0 = 1 and S1=0S_1 = 0, the select value is S1S0=01=1S_1S_0 = 01 = 1, so input I1I_1 is transferred to the output.

A Simple 2-Bit ALU

The Arithmetic Logic Unit performs the CPU’s arithmetic and logic operations. The lecture’s ALU takes two 2-bit operands A=A1A0A = A_1A_0 and B=B1B0B = B_1B_0, two function-select (control) lines f1f0f_1 f_0, and produces a 2-bit result C=C1C0C = C_1C_0 plus an overflow (carry-out) signal.

f1f0f_1 f_0OperationResult CC
00ADDarithmetic sum AA plus BB (2 bits + overflow)
01ORCi=Ai+BiC_i = A_i + B_i for each bit
10NOTCi=Ai′C_i = A_i' (each bit of AA complemented)
11ANDCi=AiBiC_i = A_i B_i for each bit

How it is built (it combines everything on this page):

  1. A 2-to-4 decoder on f1f0f_1 f_0 turns the operation code into four enable lines, exactly one active.
  2. For each bit position, an AND gate, a NOT gate (on the AA bit) and an OR gate compute all the logic results in parallel.
  3. The adder part: a half adder for bit 0 (no carry in) and a full adder for bit 1, with the carry from bit 0 feeding bit 1; the carry out of bit 1 is the overflow output.
  4. Each result is ANDed with its decoder enable line, and an OR gate per bit merges them, so only the selected operation’s result reaches C1C_1 and C0C_0. (This AND-OR selection is a multiplexer in disguise.)
2-bit ALU block diagramANDORNOT Acarrysumadder11011000decoderA, Bf1 f0COverflow

Worked Examples

Exercise 1

Draw (as a gate list) the AND-OR circuit for F(x,y,z)=x′yz+xy′z+xyzF(x, y, z) = x'yz + xy'z + xyz, then simplify FF and draw the simpler circuit. Compare the gate counts.

Show solution ↓
Solution

Original circuit:

  • Inverters: x′x', y′y' → 2 NOT gates.
  • AND gates (3-input): a1=x′yza_1 = x'yz, a2=xy′za_2 = xy'z, a3=xyza_3 = xyz → 3 AND gates.
  • OR gate (3-input): F=a1+a2+a3F = a_1 + a_2 + a_3 → 1 OR gate.

Total 6 gates.

Simplify (K-map: 1s at m3, m5, m7):

x\yzx \backslash yz00011110
00010
10110
  • Group A: m3, m7 (column 11) → yzyz.
  • Group B: m5, m7 (bottom row, columns 01 and 11) → xzxz.

F=yz+xz=z(x+y)F = yz + xz = z(x + y) (Distributive).

Simplified circuit: one OR gate x+yx + y, one AND gate z(x+y)z(x + y) → 2 gates, no inverters.

F = z(x + y)xyzx + yF

Check: z(x+y)z(x+y) is 1 when z=1z = 1 and at least one of x,yx, y is 1: rows 011, 101, 111 = m3, m5, m7 ✓. Going from 6 gates to 2 is why we simplify before building.

Exercise 2

Trace the full adder (two XORs, two ANDs, one OR, as in the lecture circuit) for the inputs x=1x = 1, y=1y = 1, Cin=1C_{in} = 1, and then for x=1x = 1, y=0y = 0, Cin=1C_{in} = 1. Give every internal signal.

Show solution ↓
Solution

Internal signals: p=x⊕yp = x \oplus y (XOR 1), g=xyg = xy (AND 1), Sum =p⊕Cin= p \oplus C_{in} (XOR 2), c2=p Cinc_2 = p\,C_{in} (AND 2), Cout=g+c2C_{out} = g + c_2 (OR).

Signalx=1,y=1,Cin=1x=1, y=1, C_{in}=1x=1,y=0,Cin=1x=1, y=0, C_{in}=1
p=x⊕yp = x \oplus y1⊕1=01 \oplus 1 = 01⊕0=11 \oplus 0 = 1
g=xyg = xy1100
Sum =p⊕Cin= p \oplus C_{in}0⊕1=10 \oplus 1 = 11⊕1=01 \oplus 1 = 0
c2=p⋅Cinc_2 = p \cdot C_{in}0011
Cout=g+c2C_{out} = g + c_21+0=11 + 0 = 10+1=10 + 1 = 1
result Cout SumC_{out}\,\text{Sum}112=311_2 = 3102=210_2 = 2

Check against arithmetic: 1+1+1=3=1121 + 1 + 1 = 3 = 11_2 ✓ and 1+0+1=2=1021 + 0 + 1 = 2 = 10_2 ✓.

Note how the carry is produced differently: in the first case it is generated (g=1g = 1, both bits 1); in the second it is propagated (one bit is 1 and the carry in passes through).

Exercise 3

A 4-bit ripple-carry adder computes A+BA + B with A=10112A = 1011_2 and B=01102B = 0110_2. Trace each full adder from bit 0 to bit 3, giving its inputs, Sum and Carry Out. What is the result, and does it fit in 4 bits?

Show solution ↓
Solution

Bit 0 has Cin=0C_{in} = 0; each later stage takes the previous stage’s carry out.

StageAiA_iBiB_iCinC_{in}Ai+Bi+CinA_i + B_i + C_{in}Sum SiS_iCoutC_{out}
bit 0100110
bit 1110201
bit 2011201
bit 3101201

Reading the sums from bit 3 down: S3S2S1S0=0001S_3S_2S_1S_0 = 0001, with final carry C4=1C_4 = 1. The full result is 1 00012=171\,0001_2 = 17.

Check: 10112=111011_2 = 11, 01102=60110_2 = 6, 11+6=17=10001211 + 6 = 17 = 10001_2 ✓.

As an unsigned 4-bit number the answer does not fit (max 15): the carry out C4=1C_4 = 1 signals this. Notice the carry rippling: stage 1 had to wait for stage 0’s carry (0), stage 2 for stage 1’s (1), and stage 3 for stage 2’s (1).

Exercise 4

(a) How many inputs does a decoder with 16 outputs have? How many outputs does a decoder with 10 inputs have?

(b) A 32-word memory is built from 8 chips of 4 words each, and addresses are 5 bits A4A3A2A1A0A_4A_3A_2A_1A_0. A decoder chooses the chip. Which bits go to the decoder, what size is it, and which chip and which word inside it does address 10110210110_2 select?

Show solution ↓
Solution

(a) nn inputs give 2n2^n outputs.

  • 2n=16⇒n=log⁡216=42^n = 16 \Rightarrow n = \log_2 16 = 4 inputs (a 4-to-16 decoder).
  • 10 inputs → 210=10242^{10} = 1024 outputs (a 10-to-1024 decoder, enough to select any of 1024 memory locations).

(b) 8 chips need log⁡28=3\log_2 8 = 3 bits to pick a chip, and 4 words per chip need log⁡24=2\log_2 4 = 2 bits to pick a word. Use the high bits for the chip:

  • A4A3A2A_4A_3A_2 → a 3-to-8 decoder; each of its 8 outputs enables one chip.
  • A1A0A_1A_0 → go to all chips and select the word within the enabled chip.

Address 10110210110_2: A4A3A2=1012=5A_4A_3A_2 = 101_2 = 5 → decoder output 5 is active → chip 5 is enabled. A1A0=102=2A_1A_0 = 10_2 = 2 → word 2 of chip 5.

Check: chip 5 holds addresses 5×4=205 \times 4 = 20 to 2323; word 2 is address 22=10110222 = 10110_2 ✓.

Exercise 5

A 4-to-1 multiplexer has data inputs I3I2I1I0=1001I_3I_2I_1I_0 = 1001.

(a) Using the internal equation, find the output when S1=0S_1 = 0, S0=1S_0 = 1.

(b) Give the output for all four select values.

(c) How many select lines does an 8-input mux need? A 32-input mux?

Show solution ↓
Solution

I3=1I_3 = 1, I2=0I_2 = 0, I1=0I_1 = 0, I0=1I_0 = 1.

(a) Output=S1′S0′I0+S1′S0I1+S1S0′I2+S1S0I3\text{Output} = S_1'S_0'I_0 + S_1'S_0I_1 + S_1S_0'I_2 + S_1S_0I_3 with S1=0S_1 = 0, S0=1S_0 = 1 (so S1′=1S_1' = 1, S0′=0S_0' = 0):

AND gateSelect factorsDataGate output
S1′S0′I0S_1'S_0'I_01⋅01 \cdot 010
S1′S0I1S_1'S_0I_11⋅11 \cdot 100 (this is the selected gate)
S1S0′I2S_1S_0'I_20⋅00 \cdot 000
S1S0I3S_1S_0I_30⋅10 \cdot 110

Output =0+0+0+0=0= 0 + 0 + 0 + 0 = 0, which is I1I_1 ✓.

(b)

S1S0S_1S_0selected inputOutput
00I0I_01
01I1I_10
10I2I_20
11I3I_31

(c) Select lines =log⁡2(inputs)= \log_2(\text{inputs}): log⁡28=3\log_2 8 = 3; log⁡232=5\log_2 32 = 5.

Exercise 6

Implement a full adder using a 3-to-8 decoder and OR gates.

Show solution ↓
Solution

Feed x,y,Cinx, y, C_{in} into the decoder (as a 3-bit number, xx the most significant bit). Output DkD_k is active exactly when the input equals kk, i.e. DkD_k is minterm mkm_k.

From the full adder table (4.2): Sum =Σm(1,2,4,7)= \Sigma m(1, 2, 4, 7) and Cout=Σm(3,5,6,7)C_{out} = \Sigma m(3, 5, 6, 7). So:

Sum=D1+D2+D4+D7,Cout=D3+D5+D6+D7\text{Sum} = D_1 + D_2 + D_4 + D_7, \qquad C_{out} = D_3 + D_5 + D_6 + D_7

Hardware: one 3-to-8 decoder and two 4-input OR gates (D0D_0 is unused).

Full adder from a 3-to-8 decoderxyCinD0D1D2D3D4D5D6D7decoderxyCin3-to-8SumCarry out

Check with xyCin=110x y C_{in} = 110 (= 6): only D6D_6 is 1. Sum =0= 0 (6 is not in its list), Cout=1C_{out} = 1 (6 is in its list) → 102=2=1+1+010_2 = 2 = 1 + 1 + 0 ✓.

Exercise 7

For the lecture’s 2-bit ALU (f1f0f_1f_0: 00 ADD, 01 OR, 10 NOT, 11 AND), give the output C1C0C_1C_0 (and the overflow/carry-out) for:

(a) A=01A = 01, B=10B = 10 under each of the four operations.

(b) A=11A = 11, B=01B = 01 with f1f0=00f_1f_0 = 00.

Show solution ↓
Solution

(a) A1A0=01A_1A_0 = 01, B1B0=10B_1B_0 = 10. The decoder activates exactly one enable line; the others force their results to 0 before the per-bit OR.

f1f0f_1f_0Active operationbit 1bit 0C1C0C_1C_0overflow
11AND0⋅1=00 \cdot 1 = 01⋅0=01 \cdot 0 = 0000
01OR0+1=10 + 1 = 11+0=11 + 0 = 1110
10NOT AA0′=10' = 11′=01' = 0100
00ADDsee below110

ADD: bit 0 half adder: A0+B0=1+0A_0 + B_0 = 1 + 0 → sum 1, carry 0. Bit 1 full adder: A1+B1+c=0+1+0A_1 + B_1 + c = 0 + 1 + 0 → sum 1, carry out 0. Result 112=3=1+211_2 = 3 = 1 + 2 ✓.

(b) A=11A = 11, B=01B = 01, ADD:

  • Bit 0 (half adder): 1+11 + 1 → C0=1⊕1=0C_0 = 1 \oplus 1 = 0, carry =1⋅1=1= 1 \cdot 1 = 1.
  • Bit 1 (full adder): 1+0+11 + 0 + 1 → C1=1⊕0⊕1=0C_1 = 1 \oplus 0 \oplus 1 = 0, carry out =1⋅0+1⋅(1⊕0)=1= 1\cdot0 + 1\cdot(1 \oplus 0) = 1.

C1C0=00C_1C_0 = 00 with overflow = 1. The true sum 3+1=4=10023 + 1 = 4 = 100_2 needs 3 bits; the 2-bit result has wrapped around and the overflow line warns the CPU.