Lesson 13 +40 XP

Multiplexers & Implementing Boolean Functions with a MUX

Multiplexers & Implementing Boolean Functions with a MUX

A multiplexer (MUX) is a digital switch. It has 2n data inputs, n select lines and one output, and connects the input chosen by the select lines to the output. Multiplexers route data inside a CPU (which register goes onto the bus, which value goes into the ALU), share one transmission line among many signals, and, as this lesson shows, can implement any Boolean function without a single extra gate. This is a favourite IPU exam question.

1. The 2-to-1 Multiplexer

SY
0I0
1I1
Y = S' I0 + S I1

Two AND gates, one OR gate and an inverter. When S = 0 the upper AND gate is enabled and I0 passes; when S = 1 the lower one passes I1.

2. The 4-to-1 Multiplexer

S1S0Y
00I0
01I1
10I2
11I3
Y = S1' S0' I0 + S1' S0 I1 + S1 S0' I2 + S1 S0 I3

Each AND gate receives one data input and one minterm of the select lines, so a MUX is a decoder (on the select lines) whose outputs are ANDed with the data inputs and ORed together. In general, a 2n-to-1 MUX computes

Y = ∑i=02n - 1 mi Ii quad where mi is minterm i of the select lines.

2-to-1 and 4-to-1 multiplexer circuits2-to-1 and 4-to-1 multiplexer circuits

Enable input and quad multiplexers

Practical MUX ICs have an enable (strobe) input: when disabled, the output is 0 regardless of the select lines. The 74157 is a quad 2-to-1 MUX: four 2-to-1 multiplexers sharing one select line and one enable, so it selects one of two 4-bit words. The 74151 is an 8-to-1 MUX and the 74153 a dual 4-to-1 MUX.

3. Building Larger Multiplexers (MUX Trees)

Large multiplexers are built from smaller ones arranged as a tree. The low select bits drive the first level and the high select bits the later levels.

SolvedExample 1 · An 8-to-1 MUX from 4-to-1 and 2-to-1 MUXes

Build an 8-to-1 MUX using two 4-to-1 MUXes and one 2-to-1 MUX.

  1. First level: MUX A gets I0 ldots I3, MUX B gets I4 ldots I7. Both use S1 S0.
  2. Second level: a 2-to-1 MUX chooses between the outputs of A and B using S2.
  3. Check: S2 S1 S0 = 110: both first-level MUXes select their input 2, giving I2 and I6; then S2 = 1 selects I6. Correct.
Answer3 multiplexers in two levels
SolvedExample 2 · A 16-to-1 MUX from 4-to-1 MUXes

How many 4-to-1 MUXes are needed for a 16-to-1 MUX?

  1. First level: 16 inputs / 4 = 4 MUXes, all driven by S1 S0.
  2. Second level: their 4 outputs go into 1 more 4-to-1 MUX, driven by S3 S2.
Answer5 four-to-one multiplexers

8-to-1 MUX tree and 16-to-1 MUX tree8-to-1 MUX tree and 16-to-1 MUX tree

A general count: a 2n-to-1 MUX from 2-to-1 MUXes needs 2n - 1 of them in n levels.

  1. Implementing a Function with a MUX: All Variables as Selects

Since Y = ∑ mi Ii, a function of n variables is realised by a 2n-to-1 MUX with:

  • the n variables on the select lines;
  • Ii = 1 for each minterm in the function, and Ii = 0 otherwise.

For example F(A, B, C) = ∑ m(1, 3, 5, 6) on an 8-to-1 MUX: I1 = I3 = I5 = I6 = 1 and all other inputs 0. Simple, but it wastes a large MUX.

  1. Using a Smaller MUX: n − 1 Selects and the Implementation Table

A function of n variables can be built with a 2n-1-to-1 MUX (half the size):

  1. Use n - 1 variables as the select lines. The remaining variable (call it the data variable) feeds the data inputs.
  2. Each data input then receives one of four things: 0, 1, the data variable, or its complement.

The implementation table method

Choose the data variable to be the MSB (for example A), with the other variables on the selects.

  1. Draw a table with columns I0 ldots I2n-1 - 1 and two rows: row A' lists minterms 0 ldots 2n-1 - 1, row A lists the rest.
  2. Circle the minterms of the function.
  3. For each column:
Circled in the columnData input Ii
neither0
both1
only the lower (A) rowA
only the upper (A') rowA'
SolvedExample 3 · A 3-variable function on a 4-to-1 MUX

Implement F(A, B, C) = ∑ m(1, 3, 5, 6) using a 4-to-1 MUX with B, C as selects.

I0I1I2I3
A'0(1)2(3)
A4(5)(6)7
Input01AA'
  1. I0: neither 0 nor 4 is in F, so I0 = 0.
  2. I1: both 1 and 5 are in F, so I1 = 1.
  3. I2: only 6 (the A row), so I2 = A.
  4. I3: only 3 (the A' row), so I3 = A'.
AnswerS1 = B, S0 = C; I0 = 0, I1 = 1, I2 = A, I3 = A'

Why it works: with B C = 10 the MUX outputs I2, and F must then be 1 only for minterm 6 (A = 1) and not for minterm 2 (A = 0): that is exactly F = A.

SolvedExample 4 · A 4-variable function on an 8-to-1 MUX (Mano)

Implement F(A, B, C, D) = ∑ m(1, 3, 4, 11, 12, 13, 14, 15) with an 8-to-1 MUX.

I0I1I2I3I4I5I6I7
A'0(1)2(3)(4)567
A8910(11)(12)(13)(14)(15)
Input0A'011AAA
  1. Selects: S2 S1 S0 = B C D.
  2. Read each column with the rule above.
AnswerI0 = 0, I1 = A', I2 = 0, I3 = 1, I4 = 1, I5 = I6 = I7 = A

Example 4 implemented with an 8-to-1 MUXExample 4 implemented with an 8-to-1 MUX

Verifying Example 4 in Verilog

The testbench connects the data inputs exactly as the implementation table says, sweeps all 16 input combinations, and prints where F = 1. It must reproduce the original minterm list:

VERILOG
// 4-to-1 and 8-to-1 multiplexers, and F(A,B,C,D) = sum m(1,3,4,11,12,13,14,15) on an 8-to-1 MUX
module mux4 (
    input  [3:0] i,
    input  [1:0] s,
    output       y
);
    assign y = i[s];
endmodule

module mux8 (
    input  [7:0] i,
    input  [2:0] s,
    output       y
);
    wire y0, y1;
    mux4 lo (.i(i[3:0]), .s(s[1:0]), .y(y0));   // two 4-to-1 MUXes ...
    mux4 hi (.i(i[7:4]), .s(s[1:0]), .y(y1));
    assign y = s[2] ? y1 : y0;                  // ... and a 2-to-1 MUX
endmodule

module tb;
    reg  a, b, c, d;
    wire f;
    integer k;

    // implementation table result: I0..I7 = 0, A', 0, 1, 1, A, A, A
    mux8 m (.i({a, a, a, 1'b1, 1'b1, 1'b0, ~a, 1'b0}), .s({b, c, d}), .y(f));

    initial begin
        $write("F = 1 at minterms:");
        for (k = 0; k < 16; k = k + 1) begin
            {a, b, c, d} = k;
            #1;
            if (f) $write(" %0d", k);
        end
        $display("");
    end
endmodule

The MUX circuit gives back exactly the required minterms:

OUTPUT
F = 1 at minterms: 1 3 4 11 12 13 14 15

In the port list {a, a, a, 1'b1, 1'b1, 1'b0, ~a, 1'b0} the leftmost element is I7 and the rightmost is I0, because Verilog concatenation lists the most significant bit first. mux8 is built as a tree, exactly as in Example 1.

Choosing a different data variable

The data variable does not have to be the MSB. If the LSB (C in a 3-variable function) is used instead, the selects are A, B and the minterms pair up as (0, 1), (2, 3), (4, 5), (6, 7): compare the two minterms of each pair. For F = ∑ m(1, 3, 5, 6) that gives I0 = C, I1 = C, I2 = C, I3 = C'. Different choices can give simpler inputs.

6. The MUX as a Universal Element

A 2-to-1 MUX alone can make every basic gate, so it is a universal building block (FPGAs are built from multiplexer-based look-up tables):

GateSelectI0I1Output
NOT AA10A'
ANDA0BAB
ORAB1A + B
XORABB'A oplus B

7. Multiplexer vs Demultiplexer

FeatureMultiplexerDemultiplexer
Functionmany inputs to one output (data selector)one input to many outputs (data distributor)
Inputs / outputs2n data in, 1 out1 data in, 2n out
Select linesnn
Related todecoder + OR gatedecoder with enable
Useparallel to serial conversion, bus selection, function generatorserial to parallel conversion, routing

Time-sharing one line with a MUX and DEMUXTime-sharing one line with a MUX and DEMUX

💡 Tip

Key points to remember

  • 2n-to-1 MUX: Y = ∑ mi Ii over the select minterms.
  • MUX trees: low select bits at the first level; 16-to-1 needs five 4-to-1 MUXes.
  • With all n variables as selects, Ii is 1 or 0. With n - 1 selects, each Ii is 0, 1, the data variable or its complement.
  • Implementation table: neither circled 0, both 1, lower row only A, upper row only A'.
  • A 2-to-1 MUX is universal.
🎯 END-TERM EXAM PREP

📝 IPU End-Term Exam Corner (5-10 Marks)

  • Q1. What is a multiplexer? Draw the logic diagram of a 4-to-1 MUX and write its output expression. (5 Marks)
  • Q2. Implement F(A, B, C, D) = ∑ m(1, 3, 4, 11, 12, 13, 14, 15) using an 8-to-1 multiplexer. (10 Marks)
  • Write: the implementation table with circled minterms, the input values, and the MUX diagram with B, C, D on the selects.
  • Q3. Implement F(A, B, C) = ∑ m(1, 3, 5, 6) using a 4-to-1 MUX. (5 Marks)
  • Q4. Construct a 16-to-1 MUX using 4-to-1 multiplexers. (5 Marks)
  • Q5. Show that a 2-to-1 MUX can realise NOT, AND, OR and XOR. (5 Marks)