Prev Problem
Next Problem

64. Full Adder

module half_adder (
    input  a, b,
    output sum, carry
);
    xor (sum, a, b);
    and (carry, a, b);
endmodule

module full_adder_struct (
    input  a, b, cin,
    output sum, cout
);
    wire sum1, carry1, carry2;

    // First half adder
    half_adder ha1(.a(a), .b(b), .sum(sum1), .carry(carry1));

    // Second half adder
    half_adder ha2(.a(sum1), .b(cin), .sum(sum), .carry(carry2));

    // Final OR
    or (cout, carry1, carry2);
endmodule

💡Remember

  • Structural modeling = design built by instantiating smaller modules/gates.
  • Full adder = 2 half adders + OR gate.
  • Self-contained hierarchy: reusable half_adder block is defined once and reused.
  • The sum is computed twice (XOR cascaded), carry is merged with OR.