Verilog: simple Half adder

//Code
module ex1( a,b,sum,carry); // half adder
output sum,carry;
input a,b;
wire sum,carry;

xor (sum,a,b);
and (carry,a,b);
endmodule
   
//Testbench
`timescale 1ns / 1ps


module test4;

    // Inputs
    reg a;
    reg b;

    // Outputs
    wire sum;
    wire carry;

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

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

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

    end
     
endmodule

//Output

No comments:

Post a Comment