Loading lessons...
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
| S | Y |
|---|---|
| 0 | I0 |
| 1 | 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
| S1 | S0 | Y |
|---|---|---|
| 0 | 0 | I0 |
| 0 | 1 | I1 |
| 1 | 0 | I2 |
| 1 | 1 | 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
2-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.
Build an 8-to-1 MUX using two 4-to-1 MUXes and one 2-to-1 MUX.
- First level: MUX A gets I0 ldots I3, MUX B gets I4 ldots I7. Both use S1 S0.
- Second level: a 2-to-1 MUX chooses between the outputs of A and B using S2.
- Check: S2 S1 S0 = 110: both first-level MUXes select their input 2, giving I2 and I6; then S2 = 1 selects I6. Correct.
How many 4-to-1 MUXes are needed for a 16-to-1 MUX?
- First level: 16 inputs / 4 = 4 MUXes, all driven by S1 S0.
- Second level: their 4 outputs go into 1 more 4-to-1 MUX, driven by S3 S2.
8-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.
- 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.
- 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):
- Use n - 1 variables as the select lines. The remaining variable (call it the data variable) feeds the data inputs.
- 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.
- 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.
- Circle the minterms of the function.
- For each column:
| Circled in the column | Data input Ii |
|---|---|
| neither | 0 |
| both | 1 |
| only the lower (A) row | A |
| only the upper (A') row | A' |
Implement F(A, B, C) = ∑ m(1, 3, 5, 6) using a 4-to-1 MUX with B, C as selects.
| I0 | I1 | I2 | I3 | |
|---|---|---|---|---|
| A' | 0 | (1) | 2 | (3) |
| A | 4 | (5) | (6) | 7 |
| Input | 0 | 1 | A | A' |
- I0: neither 0 nor 4 is in F, so I0 = 0.
- I1: both 1 and 5 are in F, so I1 = 1.
- I2: only 6 (the A row), so I2 = A.
- I3: only 3 (the A' row), so 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.
Implement F(A, B, C, D) = ∑ m(1, 3, 4, 11, 12, 13, 14, 15) with an 8-to-1 MUX.
| I0 | I1 | I2 | I3 | I4 | I5 | I6 | I7 | |
|---|---|---|---|---|---|---|---|---|
| A' | 0 | (1) | 2 | (3) | (4) | 5 | 6 | 7 |
| A | 8 | 9 | 10 | (11) | (12) | (13) | (14) | (15) |
| Input | 0 | A' | 0 | 1 | 1 | A | A | A |
- Selects: S2 S1 S0 = B C D.
- Read each column with the rule above.
Example 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:
// 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
endmoduleThe MUX circuit gives back exactly the required minterms:
F = 1 at minterms: 1 3 4 11 12 13 14 15In 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):
| Gate | Select | I0 | I1 | Output |
|---|---|---|---|---|
| NOT A | A | 1 | 0 | A' |
| AND | A | 0 | B | AB |
| OR | A | B | 1 | A + B |
| XOR | A | B | B' | A oplus B |
7. Multiplexer vs Demultiplexer
| Feature | Multiplexer | Demultiplexer |
|---|---|---|
| Function | many inputs to one output (data selector) | one input to many outputs (data distributor) |
| Inputs / outputs | 2n data in, 1 out | 1 data in, 2n out |
| Select lines | n | n |
| Related to | decoder + OR gate | decoder with enable |
| Use | parallel to serial conversion, bus selection, function generator | serial to parallel conversion, routing |
Time-sharing one line with a MUX and DEMUX
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.
📝 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)