4:1 MUX
module mux2to1(
input I0, I1,
input S,
output Y
);
assign Y = (S == 1'b0) ? I0 : I1;
endmodule
module mux4to1(
input S1, S0,
input I3, I2, I1, I0,
output Y
);
wire Y0, Y1;
mux2to1 M1 (I0, I1, S0, Y0);
mux2to1 M2 (I2, I3, S0, Y1);
mux2to1 M3 (Y0, Y1, S1, Y);
endmodule
TOP TO DOWN APPROACH:--
// 2 : 1 Multiplexer
module mux2_1(
input I0, I1,
input S,
output Y
);
assign Y = (~S & I0) | (S & I1);
endmodule
// 4 : 1 Multiplexer (Top-Down Structural)
module mux4_1(
input I0, I1, I2, I3,
input S1, S0,
output Y
);
wire w1, w2;
// First stage
mux2_1 M1 (I0, I1, S0, w1);
mux2_1 M2 (I2, I3, S0, w2);
// Second stage
mux2_1 M3 (w1, w2, S1, Y);
endmodule