Write a Verilog code for a 8to1 MUX that inputs are 3 bits a
Solution
// Design
module mux8_1 (i0, i1, i2, i3, i4, i5, i6, i7, sel, out1);
input i0, i1, i2, i3, i4, i5, i6, i7;
input [2:0] sel;
output reg out1;
always @ (sel, i0, i1, i2, i3, i4, i5, i6, i7)
begin
case(sel)
3\'b000 : out1 = i0;
3\'b001 : out1 = i1;
3\'b010 : out1 = i2;
3\'b011 : out1 = i3;
3\'b100 : out1 = i4;
3\'b101 : out1 = i5;
3\'b110 : out1 = i6;
3\'b111 : out1 = i7;
endcase
end
endmodule
// Testbench
`timescale 1ns / 1ps
module mux8_1_tb;
reg i0, i1, i2, i3, i4, i5, i6, i7;
reg [2:0] sel;
wire out1;
integer i;
mux8_1 uut (
.i0(i0), .i1(i1), .i2(i2), .i3(i3), .i4(i4), .i5(i5), .i6(i6), .i7(i7),
.sel(sel),
.out1(out1)
);
initial
begin
$monitor ($time, \"in1 = %b sel = %b out1 = %b\", {i0, i1, i2, i3, i4, i5, i6, i7}, sel, out1);
{i0, i1, i2, i3, i4, i5, i6, i7} = 8\'hF2;
sel = 0;
for (i = 1 ; i < 8; i = i + 1)
#2 sel = i;
#2;
{i0, i1, i2, i3, i4, i5, i6, i7} = 8\'h45;
sel = 0;
for (i = 1 ; i < 8; i = i + 1)
#2 sel = i;
end
endmodule

