Prev Problem
Next Problem

64. Full Adder

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

Define the functionality of the half adder and then instantiate it twice with different parameters. Pass those parameters to the output accordingly.

Code

// Half Adder primitive
module half_adder (
    input  a, b,
    output sum, carry
);
    // Write code here
    wire [1:0] temp;
    assign temp = a+b;
    assign sum = temp[0];
    assign carry = temp[1];
endmodule

// Full Adder using 2 Half Adders
module full_adder_struct (
    input  a, b, cin,
    output sum, cout
);
    // Write code here
    wire sum1, carry1,carry2;
    half_adder h1(a,b,sum1,carry1);
    half_adder h2(cin,sum1,sum,carry2);
    assign cout = carry1|carry2;
endmodule

 

Was this helpful?
Upvote
Downvote