Full Adder

  1. Introduction

    A full adder adds two 1-bit binary numbers along with 1-bit carry-in thus generating 1-bit sum and 1-bit carry-out. If A and B are two 1-bit values input to the full adder and Cin is the carry-in from the preceeding significant bit of the calculation then the sum, S, and the carry-out, Cout, can be determined using the following Boolean expressions.
    S = A xor B xor Cin
    Cout = (A and B) or (B and Cin) or (Cin and A)
    The full adder is usually a component in a cascade of adders, which add 4, 8, 16, 32 bit binary numbers.
    The gate level design of a full adder is shown in Figure 1.

    Figure 1. Gate-Level Design of a Full Adder

  2. Truth Table

    The truth table of a typical full adder is shown in Figure 2. In the truth table A, B and Cin are the three input signals and S and Cout are the output signals.

    Figure 2. Truth table of a Full Adder.

  3. Verilog Module

    The Verilog module of full adder is shown in Figure 3. The module has three 1-bit input ports as A, B, and Cin. There two output ports as S, and Cout which are also 1-bit wide.

    Figure 3. Verilog module of a Full Adder


  4. Verilog Code of the Full Adder (fullAdder.v)



    1. `timescale 1ns / 1ps
    2. module fullAdder ( In1,
    3. In2,
    4. Cin,
    5. Sum,
    6. Cout
    7. );
    8. input In1,
    9. In2,
    10. Cin;
    11. output Sum,
    12. Cout;
    13. assign Sum = (In1 ^ In2) ^ Cin;
    14. assign Cout = (In1 & In2) | (In2 & Cin) | (Cin & In1);
    15. endmodule
    Figure 4. Verilog Code for Full Adder

  5. Verilog Code of the Test Bench of the Full Adder (fullAdder_tb.v)



    1. `timescale 1ns / 1ps
    2. module fullAdder_tb;
    3. // Inputs
    4. reg In1;
    5. reg In2;
    6. reg Cin;
    7. // Outputs
    8. wire Sum;
    9. wire Cout;
    10. //Temporary looping variable
    11. reg [2:0] i = 3'd0;
    12. // Instantiate the Unit Under Test (UUT)
    13. fullAdder uut (
    14. .In1(In1),
    15. .In2(In2),
    16. .Cin(Cin),
    17. .Sum(Sum),
    18. .Cout(Cout)
    19. );
    20. initial begin
    21. // Initialize Inputs
    22. In1 = 1'b0;
    23. In2 = 1'b0;
    24. Cin = 1'b0;
    25. // Wait 100 ns for global reset to finish
    26. #100;
    27. // Add stimulus here
    28. for = 0; i < 8; i = i + 1'b1)begin
    29. {In1,In2,Cin} = {In1,In2,Cin} + 1'b1;
    30. #20;
    31. end
    32. end
    33. endmodule
    Figure 5. Verilog Test-bench for Full Adder

  6. Timing Diagram


    Figure 6. Timing Diagram of Full Adder