// Exercise M4, chip-level version: the chips and wires of schematic 2 and
// of the breadboard.  Same ports as adder8.sv.
//
// Generated by tools/bb_lib.py from the checked breadboard wire list;
// change the layout in tools/bb_m4.py, not this file.  Synthesizable.

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

    // Connections between the chips that are not ports

    wire c4;

    // The power rails of the breadboard, for tied-off inputs

    wire gnd = 1'b0;

    //------------------------------------------------------------------------

    // U1: CD4008 4-bit full adder, pin 1 in column 8

    cd4008 i_u1
    (
        .a4        ( a [3]   ),  // Pin 1 <- button A3
        .b3        ( b [2]   ),  // Pin 2 <- B2 wire, at +5V on the breadboard
        .a3        ( a [2]   ),  // Pin 3 <- button A2
        .b2        ( b [1]   ),  // Pin 4 <- B1 wire, at GND on the breadboard
        .a2        ( a [1]   ),  // Pin 5 <- button A1
        .b1        ( b [0]   ),  // Pin 6 <- B0 wire, at +5V on the breadboard
        .a1        ( a [0]   ),  // Pin 7 <- button A0
        .carry_in  ( gnd     ),  // Pin 9 <- GND
        .s1        ( sum [0] ),  // Pin 10 -> S0
        .s2        ( sum [1] ),  // Pin 11 -> S1
        .s3        ( sum [2] ),  // Pin 12 -> S2
        .s4        ( sum [3] ),  // Pin 13 -> S3
        .carry_out ( c4      ),  // Pin 14 -> C4
        .b4        ( b [3]   )   // Pin 15 <- B3 wire, at +5V on the breadboard
    );

    //------------------------------------------------------------------------

    // U2: CD4008 4-bit full adder, pin 1 in column 18

    cd4008 i_u2
    (
        .a4        ( a [7]   ),  // Pin 1 <- button A7
        .b3        ( b [6]   ),  // Pin 2 <- B6 wire, at GND on the breadboard
        .a3        ( a [6]   ),  // Pin 3 <- button A6
        .b2        ( b [5]   ),  // Pin 4 <- B5 wire, at +5V on the breadboard
        .a2        ( a [5]   ),  // Pin 5 <- button A5
        .b1        ( b [4]   ),  // Pin 6 <- B4 wire, at GND on the breadboard
        .a1        ( a [4]   ),  // Pin 7 <- button A4
        .carry_in  ( c4      ),  // Pin 9 <- U1 pin 14 (COUT)
        .s1        ( sum [4] ),  // Pin 10 -> S4
        .s2        ( sum [5] ),  // Pin 11 -> S5
        .s3        ( sum [6] ),  // Pin 12 -> S6
        .s4        ( sum [7] ),  // Pin 13 -> S7
        .carry_out ( carry   ),  // Pin 14 -> C8
        .b4        ( b [7]   )   // Pin 15 <- B7 wire, at GND on the breadboard
    );

endmodule
