// CD4008B: 4-bit full adder with a fast carry output.
//
// Ports in pin order, named as in the datasheet: A1-A4 and B1-B4 are the
// two numbers (A1 and B1 the lowest bits), S1-S4 the sum.  The power pins,
// VSS (8) and VDD (16), are left out.  Synthesizable.
//
// Inside are four full adders.  The chip computes CARRY OUT with extra
// look-ahead logic, so it does not wait for the carry to ripple through all
// four stages; the result is the same.

module cd4008
(
    input  logic a4,         // Pin 1
    input  logic b3,         // Pin 2
    input  logic a3,         // Pin 3
    input  logic b2,         // Pin 4
    input  logic a2,         // Pin 5
    input  logic b1,         // Pin 6
    input  logic a1,         // Pin 7
                             // Pin 8:  VSS
    input  logic carry_in,   // Pin 9
    output logic s1,         // Pin 10
    output logic s2,         // Pin 11
    output logic s3,         // Pin 12
    output logic s4,         // Pin 13
    output logic carry_out,  // Pin 14
    input  logic b4          // Pin 15
                             // Pin 16: VDD
);

    assign { carry_out, s4, s3, s2, s1 } =   { 1'b0, a4, a3, a2, a1 }
                                           + { 1'b0, b4, b3, b2, b1 }
                                           + { 4'b0, carry_in };

endmodule
