SEN2201 · Week 3 · Digital Logic Structures (logic gates, combinational logic circuits)

Combinational circuits: decoder, mux, full adder, PLA

Decoder, multiplexer, full adder and the ripple-carry adder, and building any function with a PLA. Everything you need for short-answer and tracing questions.

combinational logicdecodermultiplexer (mux)select linehalf adderfull addercarry incarry outripple-carry adderprogrammable logic array (PLA)AND arrayOR array

On the previous page you saw gates. On this page you will learn four building blocks made from them that are found in every processor: the decoder, the multiplexer, the full adder and the PLA. All of them are combinational circuits: the output depends only on the current inputs, and nothing is remembered. Circuits that remember (latch, register) are the topic of week 4.

On the midterm these structures bring short-answer questions: “if the input is 101, which output is 1?”, “how many selects does a 32-to-1 mux need?”, “the output of a full adder for 1+1+0?”, “write the carries of a 4-bit adder”. You will see all of them in the LC-3 too: register selection is done with a decoder, the ALU input with a mux, and addition with an adder.

Decoder

A decoder with nn inputs has 2n2^n outputs. It reads the input as a binary number and sets the output with that number to 1 and all the rest to 0.

2-to-4 decoder
A1 A0 | D0 D1 D2 D3
 0  0 |  1  0  0  0
 0  1 |  0  1  0  0
 1  0 |  0  0  1  0
 1  1 |  0  0  0  1

D0 = A1'A0'   D1 = A1'A0   D2 = A1A0'   D3 = A1A0

Each output is an AND gate and produces exactly one minterm. Therefore:

TIP · Decoder + OR = any function. If the minterm list of a function is Σm(1,2,4,7)\Sigma m(1, 2, 4, 7), connect the D1, D2, D4, D7 outputs of a 3-to-8 decoder to an OR gate. Done.

Where is it used? To decode the opcode of an instruction (which instruction?), to decode an address in memory (which row?), to choose which register to write in a register file.

Multiplexer (mux)

A mux chooses one of 2n2^n data inputs and passes it to the output. nn select lines decide which one passes.

MuxData inputsSelect lines
2-to-121
4-to-142
8-to-183
32-to-1325

The equation of a 2-to-1 mux:

Y=S′A+SBY = S'A + SB

A 4-to-1 mux is a 2-to-4 decoder with four AND gates and an OR gate: the decoder decodes the select, and the chosen AND gate passes its own data input.

4-to-1 mux, I0..I3 = 1, 0, 0, 1
S1 S0 = 11 → I3 → output 1
S1 S0 = 01 → I1 → output 0

Building a function with a mux

You can build a function of n+1n+1 variables with a 2n2^n-to-1 mux. Connect the first nn variables to the select. Split the table into groups of two rows according to these variables. In each group F, in terms of the last variable (C), is one of these four things: 0, 1, C, C’.

Example: F(A,B,C)=Σm(0,3,4,5)F(A,B,C) = \Sigma m(0, 3, 4, 5), select = AB.

ABrowsFto input
00m0 = 1, m1 = 01 when C = 0I0=C′I_0 = C'
01m2 = 0, m3 = 11 when C = 1I1=CI_1 = C
10m4 = 1, m5 = 1always 1I2=1I_2 = 1
11m6 = 0, m7 = 0always 0I3=0I_3 = 0

Adders

Half adder

It adds two bits: S=A⊕BS = A \oplus B, C=ABC = AB. It cannot take an incoming carry, so it is useful only at the rightmost bit.

Full adder

It adds three bits: A, B and the CinC_{in} coming from the right. It has two outputs: the right bit of the sum, S, and the CoutC_{out} going to the left.

ABCinCoutS
00000
00101
01001
01110
10001
10110
11010
11111

Do not memorize the table, just add the three bits: 1+1+1 = 3 = 11 → Cout = 1, S = 1. The equations:

S=A⊕B⊕CinCout=AB+ACin+BCinS = A \oplus B \oplus C_{in} \qquad C_{out} = AB + AC_{in} + BC_{in}

S is 1 when the number of 1s is odd (odd parity). Cout is 1 when at least two inputs are 1 (majority).

Ripple-carry adder

To add two nn-bit numbers, nn full adders are placed side by side. The CoutC_{out} of each is connected to the CinC_{in} of the one on its left. The CinC_{in} of the rightmost is 0. The carry moves from right to left, “rippling” along.

Worked example: 0111 + 0101

carry in:   1 1 1 0
            0 1 1 1    (7)
          + 0 1 0 1    (5)
          ---------
            1 1 0 0    (12), Cout = 0

bit0: 1+1+0 = 10 → S=0, c=1
bit1: 1+0+1 = 10 → S=0, c=1
bit2: 1+1+1 = 11 → S=1, c=1
bit3: 0+0+1 = 01 → S=1, c=0

This adder is the same circuit for unsigned and 2’s complement. In 2’s complement, because 0111 + 0101 = 1100 (two positives → negative), there is overflow; this is the hardware counterpart of the rule from week 2. For subtraction, every bit of B is NOTed and the rightmost CinC_{in} is made 1: A+B′+1=A−BA + B' + 1 = A - B.

PLA (programmable logic array)

A PLA is a ready-made piece of hardware for the idea “build every function as SOP”. It has two layers:

  1. AND array: produces product terms from the inputs and their complements.
  2. OR array: connects the desired terms to the OR gate of each output.

The connections are “programmed”: which AND gate goes to which OR is chosen. A term can be shared by several outputs.

Example: F1=Σm(0,3)F_1 = \Sigma m(0, 3), F2=Σm(3,5,6)F_2 = \Sigma m(3, 5, 6). The distinct minterms needed are 0, 3, 5, 6. 4 gates are enough in the AND array; the gate of m3 is connected to both OR gates.

A full PLA with 3 inputs produces at most 8 distinct minterms. With nn inputs, 2n2^n.

Combinational versus sequential

CombinationalSequential
What does the output depend on?only the current inputthe input and the past (state)
Memorynoneyes
Examplesdecoder, mux, adder, PLAlatch, flip-flop, register, FSM
Week34

Common mistakes

Wrong ideaThe truth
More than one output of a decoder can be 1Exactly one output is always 1
A 3-to-8 decoder has 3 outputs3 inputs, 8 outputs
A 32-to-1 mux needs 32 selects25=322^5 = 32, so 5 selects
The mux select and the data input are the same thingThe select chooses, the data passes
Full adder 1+1+1: S=0, Cout=13 = 11 → S=1, Cout=1
Cout = A⊕B⊕CinThat is the formula of S; Cout is majority
A separate adder is needed for 2’s complementThe same circuit, only the overflow interpretation differs
In a PLA each output produces its own termsTerms are shared

Test yourself

Exam-style questions. Solve them on paper first, then reveal the answer.

Question 1easy

A 3-to-8 decoder has input A2A1A0 = 110. Which output is 1?

Show answer
D6

A decoder reads the input as a binary number and sets the output with that number to 1. 110 = 6 → D6 = 1, the other seven outputs are 0.

Question 2easy

How many outputs does a decoder with 5 inputs have, and how many of them are 1 at the same time?

Show answer
32 outputs, exactly one is 1

A decoder with nn inputs has 2n2^n outputs: 25=322^5 = 32. Each input combination selects exactly one output.

Question 3medium

Write the Boolean expression of output D2 of a 2-to-4 decoder with inputs A1 (MSB) and A0.

Show answer
A1 A0'

D2 is 1 when the inputs are 10. The minterm of this single row: A1 = 1 → A1, A0 = 0 → A0'. So D2 = A1·A0'. Every decoder output is a minterm.

Question 4easy

How many select lines does an 8-to-1 multiplexer need?

Show answer
3

To choose one of 2n2^n data inputs, nn select lines are needed. 8=238 = 2^3 → 3.

Question 5easy

An 8-to-1 mux has data inputs I0..I7 = 0, 1, 1, 0, 1, 0, 0, 1 and select S2S1S0 = 101. What is the output?

Show answer
0

101 = 5 → the output is I5. Count from zero in the list: I0=0, I1=1, I2=1, I3=0, I4=1, I5=0. The output is 0.

Question 6medium

Write the output equation of a 2-to-1 multiplexer with data inputs A, B and select S (S = 0 selects A).

Show answer
Y = S'A + SB

When S = 0, the term S'A passes A and the term SB is 0. When S = 1, the opposite. If you see this expression in a circuit-reading question, say 'this is a mux'.

Question 7easy

Give S and Cout of a full adder for A = 1, B = 0, Cin = 1.

Show answer
S = 0, Cout = 1

1 + 0 + 1 = 2 = 10 (binary). The right bit is S = 0, the left bit is Cout = 1. With the formulas: S = 1⊕0⊕1 = 0, Cout = AB + ACin + BCin = 0 + 1 + 0 = 1.

Question 8medium

Write the sum S and carry-out of a full adder as Boolean expressions of A, B and Cin.

Show answer
S = A⊕B⊕Cin, Cout = AB + ACin + BCin

S is 1 when an odd number of the inputs are 1: Σm(1,2,4,7) = A⊕B⊕Cin. Cout is 1 when at least two inputs are 1: Σm(3,5,6,7) = AB + ACin + BCin (majority).

Question 9medium

A 4-bit ripple-carry adder computes 1011 + 0110 with C0 = 0. Give the 4-bit sum, the final carry-out, and the carry into each bit (bit 3 to bit 0).

Show answer
Sum 0001, Cout = 1, carries 1100

From the right: bit0: 1+0+0 = 1, c=0. bit1: 1+1+0 = 10 → 0, c=1. bit2: 0+1+1 = 10 → 0, c=1. bit3: 1+0+1 = 10 → 0, c=1.
The sum is 0001, with a 1 out. The carries into the bits (bit3..bit0) are 1 1 0 0. Check: 11 + 6 = 17 = 1 0001.

Question 10medium

Using a 3-to-8 decoder and one OR gate, which decoder outputs must be ORed to implement F(A,B,C) = A ⊕ B ⊕ C?

Show answer
D1, D2, D4, D7

A⊕B⊕C is 1 on the rows with an odd number of 1s: 001, 010, 100, 111 → m1, m2, m4, m7. The decoder produces each minterm on a separate output; ORing these four outputs is enough.

Question 11hard

Implement F(A,B,C) = Σm(1, 2, 6, 7) with a 4-to-1 mux whose select lines are A (MSB) and B. What goes on inputs I0, I1, I2, I3?

Show answer
I0 = C, I1 = C', I2 = 0, I3 = 1

Split the table into AB pairs and write F in terms of C in each pair.
AB = 00: m0 = 0, m1 = 1 → F = C. AB = 01: m2 = 1, m3 = 0 → F = C'. AB = 10: m4 = 0, m5 = 0 → F = 0. AB = 11: m6 = 1, m7 = 1 → F = 1.

Question 12hard

A PLA implements F1 = Σm(0, 3) and F2 = Σm(3, 5, 6) of inputs A, B, C using minterms. How many AND gates are needed in the AND array?

Show answer
4

In a PLA the AND array produces the terms and the OR array connects them to the outputs. A term can be shared among several outputs. The distinct minterms needed: {0, 3, 5, 6}, that is 4 AND gates. m3 is connected to both F1 and F2.

Verification: The decoder, mux, full adder and ripple-carry adder were simulated with node; the functions built with a mux and a decoder were compared with the target table on all input combinations (verify/SEN2201/03.mjs).

Review card

Combinational: the output depends ONLY on the current input, no memory Decoder: n inputs -> 2^n outputs, exactly ONE output is 1 (input 101 -> D5). Each output is a minterm Decoder + OR = any function (OR the minterm outputs of F) MUX: 2^n data, n select, 1 output = the selected input | 2-to-1: Y = S'A + SB F with a MUX: n variables on select, the inputs get the 0/1/C/C' form of the remaining variable Half adder: S = A⊕B, C = AB Full adder: S = A⊕B⊕Cin (odd number of 1s) | Cout = AB+ACin+BCin (majority) FA table: S = Σm(1,2,4,7), Cout = Σm(3,5,6,7) n-bit ripple-carry = n full adders, the rightmost Cin = 0, the carry flows left PLA: AND array (terms) + OR array (outputs), terms are shared