4-bit Carry Ripple Adder

  1. Introduction


    A N-bit full adder can be designed by cascading N number of 1-bit full adders. Each full adder takes a carry-in Cin, which is the carry-out Cout of the previous adder. This kind of chain of adders forms a ripple-carry adder, since each carry-bit "ripples" to the next full adder. The layout of a ripple-carry adder is simple, which allows for fast design time; however, the ripple-carry adder is relatively slow, since each full adder must wait for the carry-bit to be calculated from the previous full adder. A 4-bit ripple carry adder formed by cascading four 1-bit full adders is shown in Figure 1.

    Figure 1. 4-bit Carry Ripple Adder formed by cascading four full adders

  2. Verilog Module


    Figure 2 shows the Verilog module of a 4-bit carry ripple adder. A and B are the two 4-bit input ports which is used to read in the two 4-bit numbers that are to be summed up. The 1-bit carry-in input port Cin is used to read in a carry bit, if another instance of the ripple carry adder is cascaded towards lesser significant stage. The 4-bit sum generated by the adder is presented in the 4-bit output port Sum and 1-bit carry-out in the Cout output port. The carry out, Cout provides a carry-bit, if another instance of the ripple carry adder is cascaded towards more significant stage.

    Figure 2. Verilog module of a 4-bit Ripple Carry Adder

  3. Verilog Code for 4-bit Carry Ripple Adder (Adder4bit.v)



    1. `timescale 1ns / 1ps
    2. module Adder4bit(A,
    3. B,
    4. Cin,
    5. Sum,
    6. Cout
    7. );
    8. input [3:0] A,
    9. B;
    10. input Cin;
    11. output [3:0] Sum;
    12. output Cout;
    13. wire [2:0] transferC;
    14. fullAdder FA1 ( .In1(A[0]),
    15. .In2(B[0]),
    16. .Cin(Cin),
    17. .Sum(Sum[0]),
    18. .Cout(transferC[0])
    19. );
    20. fullAdder FA2 ( .In1(A[1]),
    21. .In2(B[1]),
    22. .Cin(transferC[0]),
    23. .Sum(Sum[1]),
    24. .Cout(transferC[1])
    25. );
    26. fullAdder FA3 ( .In1(A[2]),
    27. .In2(B[2]),
    28. .Cin(transferC[1]),
    29. .Sum(Sum[2]),
    30. .Cout(transferC[2])
    31. );
    32. fullAdder FA4 ( .In1(A[3]),
    33. .In2(B[3]),
    34. .Cin(transferC[2]),
    35. .Sum(Sum[3]),
    36. .Cout(Cout)
    37. );
    38. endmodule
    Figure 3. Verilog Code for 4-bit Ripple Carry Adder

  4. Verilog Test Bench for 4-bit Ripple Carry Adder (Adder4bit_tb.v)



    1. `timescale 1ns / 1ps
    2. module Adder4bit_tb;
    3. // Inputs
    4. reg [3:0] A;
    5. reg [3:0] B;
    6. reg Cin;
    7. // Outputs
    8. wire [3:0] Sum;
    9. wire Cout;
    10. // Instantiate the Unit Under Test (UUT)
    11. Adder4bit uut (
    12. .A(A),
    13. .B(B),
    14. .Cin(Cin),
    15. .Sum(Sum),
    16. .Cout(Cout)
    17. );
    18. initial begin
    19. // Initialize Inputs
    20. A = 4'b0;
    21. B = 4'b0;
    22. Cin = 4'b0;
    23. // Wait 100 ns for global reset to finish
    24. #100;
    25. // Add stimulus here
    26. A = 4'b1011;
    27. B = 4'b0100;
    28. Cin = 4'b0;
    29. #20;
    30. A = 4'd1111;
    31. B = 4'd1101;
    32. Cin = 4'b1;
    33. end
    34. endmodule
    Figure 4. Verilog Test-bench for 4-bit Ripple Carry Adder

  5. Timing Diagram


    Figure 5. Timing Diagram of 4-bit Carry Ripple Adder