summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nandgame/Makefile4
-rw-r--r--nandgame/arith_unit.sv27
-rw-r--r--nandgame/arith_unit_tb.sv71
-rw-r--r--nandgame/logic_unit_tb.sv3
-rw-r--r--nandgame/nandgame_types.v7
5 files changed, 108 insertions, 4 deletions
diff --git a/nandgame/Makefile b/nandgame/Makefile
index 5e16703..8a6e6ea 100644
--- a/nandgame/Makefile
+++ b/nandgame/Makefile
@@ -51,10 +51,10 @@ clean:
rm -rf *.json *.fs *.svg *.log *.dep *.vvp *.lxt2
simu: $(PROGRAM).lxt2
- gtkwave $< >/dev/null 2>&1
+# gtkwave $< >/dev/null 2>&1
simu2: verilator.$(PROGRAM)/dump.vvp
- gtkwave $< >/dev/null 2>&1
+# gtkwave $< >/dev/null 2>&1
lint: $(PROGRAM).sv
verilator --quiet --lint-only -Wall -Wno-PROCASSINIT $(PROGRAM).sv
diff --git a/nandgame/arith_unit.sv b/nandgame/arith_unit.sv
new file mode 100644
index 0000000..ebbaaf8
--- /dev/null
+++ b/nandgame/arith_unit.sv
@@ -0,0 +1,27 @@
+// nandgame logic unit
+
+`timescale 1us/1us
+
+`include "nandgame_types.v"
+
+module arith_unit #(
+ parameter DATA_WIDTH = 16
+) (
+ input [(DATA_WIDTH-1):0] X,
+ input [(DATA_WIDTH-1):0] Y,
+ input ArithCode operation,
+
+ output logic [(DATA_WIDTH-1):0] RES
+);
+
+always_comb begin
+ case (operation)
+ ARITH_PLUS: RES = X + Y;
+ ARITH_MINUS: RES = X - Y;
+ ARITH_INC: RES = X + 1;
+ ARITH_DEC: RES = X - 1;
+ default: RES = 0;
+ endcase
+end
+
+endmodule
diff --git a/nandgame/arith_unit_tb.sv b/nandgame/arith_unit_tb.sv
new file mode 100644
index 0000000..054e484
--- /dev/null
+++ b/nandgame/arith_unit_tb.sv
@@ -0,0 +1,71 @@
+`timescale 1us/1us
+
+// `include "nandgame_types.v"
+
+module arith_unit_tb (
+);
+
+logic [15:0] in1;
+logic [15:0] in2;
+ArithCode opcode;
+logic [15:0] result;
+
+ arith_unit uut (
+ .X(in1),
+ .Y(in2),
+ .operation(opcode),
+ .RES(result)
+);
+
+string filename;
+initial begin
+`ifdef DUMP_FILE_NAME
+ filename=`DUMP_FILE_NAME;
+`else
+ filename=" arith_unit.lxt2";
+`endif
+ $dumpfile(filename); $dumpvars();
+
+end
+
+initial begin
+ in1 = 13;
+ in2 = 17;
+ opcode = ARITH_PLUS;
+ #1
+ assert(result == 30);
+ #1
+ in1 = 12;
+ in2 = 4;
+ opcode = ARITH_MINUS;
+ #1
+ assert(result == 8);
+ #1
+ in1 = 12;
+ in2 = 13;
+ opcode = ARITH_MINUS;
+ #1
+ assert(result == 16'hffff);
+ #1
+ in1 = 13;
+ in2 = 17;
+ opcode = ARITH_INC;
+ #1
+ assert(result == 14);
+ #1
+ in1 = 13;
+ in2 = 17;
+ opcode = ARITH_DEC;
+ #1
+ assert(result == 12);
+ #1
+ in1 = 0;
+ in2 = 17;
+ opcode = ARITH_DEC;
+ #1
+ assert(result == 16'hffff);
+ #1
+ $finish();
+end
+
+endmodule
diff --git a/nandgame/logic_unit_tb.sv b/nandgame/logic_unit_tb.sv
index c1495c3..be5366e 100644
--- a/nandgame/logic_unit_tb.sv
+++ b/nandgame/logic_unit_tb.sv
@@ -1,7 +1,6 @@
`timescale 1us/1us
-`include "nandgame_types.v"
-
+//`include "nandgame_types.v"
module logic_unit_tb (
);
diff --git a/nandgame/nandgame_types.v b/nandgame/nandgame_types.v
index 2104d37..80e9375 100644
--- a/nandgame/nandgame_types.v
+++ b/nandgame/nandgame_types.v
@@ -4,3 +4,10 @@ typedef enum logic [1:0] {
LOGIC_XOR = 2'b10,
LOGIC_NEGT = 2'b11
} LogicCode;
+
+typedef enum logic [1:0] {
+ ARITH_PLUS = 2'b00,
+ ARITH_INC = 2'b01,
+ ARITH_MINUS = 2'b10,
+ ARITH_DEC = 2'b11
+} ArithCode;