// Exercise B3d: the 8-input gate chips 4068 (AND and NAND) and 4078 (OR
// and NOR).
//
// Generic version that matches schematic 1: inputs A-D are shared by both
// chips, and each chip has its own inputs E-H, which on the breadboard are
// wires to a rail: +5V for the 4068, GND for the 4078.  Synthesizable.

module gates_8_input
(
    input  logic       a,
    input  logic       b,
    input  logic       c,
    input  logic       d,
    input  logic [3:0] rest_and,  // E-H of the 4068, rest_and [0] is E
    input  logic [3:0] rest_or,   // E-H of the 4078, rest_or [0] is E

    output logic       y_and,     // 1 only when all eight inputs of the 4068 are 1
    output logic       y_nand,
    output logic       y_or,      // 0 only when all eight inputs of the 4078 are 0
    output logic       y_nor
);

    wire [7:0] and_inputs = { rest_and, d, c, b, a };
    wire [7:0] or_inputs  = { rest_or,  d, c, b, a };

    assign y_and  =   & and_inputs;
    assign y_nand = ~& and_inputs;
    assign y_or   =   | or_inputs;
    assign y_nor  = ~| or_inputs;

endmodule
