blob: 89fe8fbd2f9ad0ef003a4876806e0c2f40557e3b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// 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
) (
input [(DATA_WIDTH-1):0] X,
input [(DATA_WIDTH-1):0] Y,
input LogicCode operation,
output logic [(DATA_WIDTH-1):0] RES
);
// learning: instead of this nested ternary...
// assign RES = operation == LOGIC_AND ? (X & Y) :
// operation == LOGIC_OR ? (X | Y) :
// operation == LOGIC_XOR ? (X ^ Y) :
// operation == LOGIC_NEGT ? (~X) : 0;
// ... you can do this:
always_comb begin
case (operation)
LOGIC_AND: RES = X & Y;
LOGIC_OR: RES = X | Y;
LOGIC_XOR: RES = X ^ Y;
LOGIC_NEGT: RES = ~X;
default: RES = 0;
endcase
end
endmodule
`endif
|