// Exercise M2: a full adder from basic gates.
//
// Generic version that matches schematic 1, not tied to any chip: it adds
// three bits, A, B and the carry in.  Two XOR gates make the sum; two AND
// gates and an OR gate make the carry out.  Synthesizable.

module full_adder
(
    input  logic a,
    input  logic b,
    input  logic cin,

    output logic cout,  // Carry out: weight 2
    output logic s      // Sum:       weight 1
);

    wire p = a ^ b;     // A XOR B: 1 when exactly one of A and B is 1

    assign s    = p ^ cin;
    assign cout = a & b | p & cin;

endmodule
