Tuesday 6 June 2017

Verilog: Simple AND operation

// code

module ex1( c,a,b   );
output c;
input a,b;
wire c;
assign c=a&b;
endmodule


//Testbench

`timescale 1ns / 1ps

module test1;

    // Inputs
    reg a;
    reg b;

    // Outputs
    wire c;

    // Instantiate the Unit Under Test (UUT)
    ex1 uut (
        .c(c),
        .a(a),
        .b(b)
    );

    initial begin
        // Initialize Inputs
        a = 0;
        b = 0;

        // Wait 100 ns for global reset to finish
        #100;
       
       
       
        // Add stimulus here
a=1'b1;
    b=1'b1;
    #100;
        a=1'b1;
    b=1'b1;
    #100;
       
    a=1'b0;
    b=1'b1;
    #100;
   
    a=1'b1;
    b=1'b1;
    #100;
     
    a=1'b1;
    b=1'b0;
    #100;
    end
   

endmodule

//Output