summaryrefslogtreecommitdiff
path: root/nandgame/logic_unit.sv
diff options
context:
space:
mode:
authoruvok2026-01-01 15:32:54 +0100
committeruvok2026-01-01 15:32:54 +0100
commit981f86a5b3ea6a05925c807bac26986e0c876dcf (patch)
treed7caeb81fdd8d362ca6e4af79fa4c15e8f67d4dd /nandgame/logic_unit.sv
parent4792fb03e5d39da03633e71ff4b5375709bfb1d5 (diff)
Add nandgame files
need/want systemverilog
Diffstat (limited to 'nandgame/logic_unit.sv')
-rw-r--r--nandgame/logic_unit.sv32
1 files changed, 32 insertions, 0 deletions
diff --git a/nandgame/logic_unit.sv b/nandgame/logic_unit.sv
new file mode 100644
index 0000000..32b9691
--- /dev/null
+++ b/nandgame/logic_unit.sv
@@ -0,0 +1,32 @@
+// nandgame logic unit
+
+`timescale 1us/1us
+
+`include "nandgame_types.v"
+
+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
+);
+
+// assign RES = operation == LOGIC_AND ? (X & Y) :
+// operation == LOGIC_OR ? (X | Y) :
+// operation == LOGIC_XOR ? (X ^ Y) :
+// operation == LOGIC_NEGT ? (~X) : 0;
+
+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