Verilog: Full Adder using stratural style of modeling

//code
module full_adder( a,b,cin,sum,carry); // fulladder
output sum,carry;
input a,b,cin;
wire sum,carry;
wire x1,x2,x3;
xor (x1,a,b);
and (x2,a,b);
xor(sum,cin,x1);
and (x3,x1,cin);
or(carry,x3,x2);
endmodule

//Testbench

`timescale 1ns / 1ps

////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date:   12:39:07 06/06/2017
// Design Name:   full_adder
// Module Name:   D:/PICT/WORKSHOP/workshop on verilog/exapmples/ex1/half_adder/test5.v
// Project Name:  half_adder
// Target Device: 
// Tool versions: 
// Description:
//
// Verilog Test Fixture created by ISE for module: full_adder
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
////////////////////////////////////////////////////////////////////////////////

module test5;

    // Inputs
    reg a;
    reg b;
    reg cin;

    // Outputs
    wire sum;
    wire carry;

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

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

        // Wait 100 ns for global reset to finish
        #100;
      a = 1;
        b = 1;
        cin = 0;
        #100;
        a = 1;
        b = 1;
        cin = 1;
        #100;   
        a = 1;
        b = 0;
        cin = 1;
        #100;   
           
        // Add stimulus here

    end
     
endmodule

//Output


No comments:

Post a Comment