// Exercise M3: a 2-bit adder from a half adder and a full adder.
//
// Generic version that matches schematic 1, not tied to any chip.  Bit 0
// is a half adder; its carry goes into a full adder for bit 1, whose carry
// is bit 2 of the sum.  Synthesizable.

module two_bit_adder
(
    input  logic a1,
    input  logic a0,
    input  logic b1,
    input  logic b0,

    output logic s2,  // Weight 4: the carry out of bit 1
    output logic s1,  // Weight 2
    output logic s0   // Weight 1
);

    // Bit 0: a half adder

    wire c0 = a0 & b0;

    assign s0 = a0 ^ b0;

    // Bit 1: a full adder with the carry from bit 0

    wire p1 = a1 ^ b1;

    assign s1 = p1 ^ c0;
    assign s2 = a1 & b1 | p1 & c0;

endmodule
