// Exercise M4: an 8-bit adder made of two 4-bit adders, the carry out of
// the low one into the carry in of the high one, like two cascaded 4008s.
//
// Generic version that matches schematic 1, not tied to any chip.  carry is
// the ninth bit of the sum: 1 when a + b > 255.  Synthesizable.

module adder8
(
    input  logic [7:0] a,
    input  logic [7:0] b,
    output logic [7:0] sum,
    output logic       carry
);

    // The low adder adds bits 3-0 with no carry in; its carry out C4 goes
    // into the high adder, which adds bits 7-4

    wire [4:0] low  = 5' (a [3:0]) + 5' (b [3:0]);
    wire [4:0] high = 5' (a [7:4]) + 5' (b [7:4]) + 5' (low [4]);

    assign sum   = { high [3:0], low [3:0] };
    assign carry = high [4];

endmodule
