Verilog - Mux, Demux, Encoder, Decoder
Verilog - Mux, Demux, Encoder, Decoder
Select/Switc Out
h
0 I0
1 I1
Y = I0.S’ + I1.S
Verilog Code
If else Statement Case Statement Testbench
module m2to1b( i0, i1, s, y); module m2to1b(y,i0,i1,s); module mux2to1_tb;
input i0; wire y;
input wire i0, i1, s; input i1;
reg i0,i1,s;
output reg y; mux2to1b
input s; m1(.y(y),.i0(i0),.i1(i1),.s(s));
always @(s) output y; initial
begin reg y; begin
if(s) always @ (s) i0=1'b0; i1=1'b0; s=1'b0;
case (s) #10 i0=1'b1; i1=1'b0; s=1'b0;
y= i1; 0: y = i0; #10 i0=1'b0; i1=1'b1; s=1'b1;
else 1: y = i1; #10 i0=1'b1; i1=1'b0; s=1'b1;
end
y=i0; default: y = 1'bx;
endmodule
end endcase
endmodule endmodule
Verilog Code