Verilog: 2:1 Mux using conditional operator

//code

module ex1( out,I1,I2,S); // 2:1 mux
output out;
input I1,I2,S;
wire out;

assign out=S?I1:I2;
endmodule
     

//Testbench

`timescale 1ns / 1ps

module test3;

    // Inputs
    reg I1;
    reg I2;
    reg S;

    // Outputs
    wire out;

    // Instantiate the Unit Under Test (UUT)
    ex1 uut (
        .out(out),
        .I1(I1),
        .I2(I2),
        .S(S)
    );

    initial begin
        // Initialize Inputs
        I1 = 0;
        I2 = 0;
        S = 0;

        // Wait 100 ns for global reset to finish
        #100;
        I1=1'b0;
          I2=1'b1;
          S=1'b0;
          #100;
            I1=1'b1;
          I2=1'b0;
          S=1'b1;
          #100;
         
           I1=1'b0;
          I2=1'b1;
          S=1'b1;
          #100;
         
         
        // Add stimulus here

    end
     
endmodule

//Output

No comments:

Post a Comment