// nandgame logic unit `timescale 1us/1us `include "nandgame_types.v" `ifndef NANDGAME_NANDGAME_LOU `define NANDGAME_NANDGAME_LOU module logic_unit #( parameter DATA_WIDTH = 16 ) ( // first operand input [(DATA_WIDTH-1):0] X_in, // second operand input [(DATA_WIDTH-1):0] Y_in, // opcode, see LogicCode input LogicCode logic_operation_in, // result of operation output logic [(DATA_WIDTH-1):0] result_out ); // learning: instead of this nested ternary... // assign result_out = logic_operation_in == LOGIC_AND ? (X_in & Y_in) : // logic_operation_in == LOGIC_OR ? (X_in | Y_in) : // logic_operation_in == LOGIC_XOR ? (X_in ^ Y_in) : // logic_operation_in == LOGIC_NEGT ? (~X_in) : 0; // ... you can do this: always_comb begin case (logic_operation_in) LOGIC_AND: result_out = X_in & Y_in; LOGIC_OR: result_out = X_in | Y_in; LOGIC_XOR: result_out = X_in ^ Y_in; LOGIC_NEGT: result_out = ~X_in; default: result_out = 0; endcase end endmodule `endif