Prev Problem
Next Problem

65. Ripple Carry Adder

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

// 1-bit Full Adder (to be used by the 4-bit RCA)
module full_adder_1bit (
    input  a, b, cin,
    output sum, cout
);
    assign sum = a^b^cin;
    assign cout = a&cin | b&cin | b&a;

endmodule

// 4-bit Ripple Carry Adder – chain 4 full adders
module rca4_chain (
    input  [3:0] a,
    input  [3:0] b,
    input        cin,
    output [3:0] sum,
    output       cout
);
    // TODO: Declare internal ripple carries
    wire c_1,c_2,C_3,s_1,s_2,s_3, c_4, s_4;

    full_adder_1bit b1(.a(a[0]), .b(b[0]), .cin(cin), .sum(s_1), .cout(c_1));
    full_adder_1bit b2(.a(a[1]), .b(b[1]), .cin(c_1), .sum(s_2), .cout(c_2));
    full_adder_1bit b3(.a(a[2]), .b(b[2]), .cin(c_2), .sum(s_3), .cout(c_3));
    full_adder_1bit b4(.a(a[3]), .b(b[3]), .cin(c_3), .sum(s_4), .cout(c_4));
    
    assign sum = {s_4, s_3, s_2, s_1};
    assign cout=c_4;
endmodule

 

Was this helpful?
Upvote
Downvote