summaryrefslogtreecommitdiff
path: root/nandgame/alu_tb.sv
diff options
context:
space:
mode:
Diffstat (limited to 'nandgame/alu_tb.sv')
-rw-r--r--nandgame/alu_tb.sv190
1 files changed, 95 insertions, 95 deletions
diff --git a/nandgame/alu_tb.sv b/nandgame/alu_tb.sv
index cb5bfa5..1b05401 100644
--- a/nandgame/alu_tb.sv
+++ b/nandgame/alu_tb.sv
@@ -4,20 +4,20 @@
module alu_tb;
-logic [15:0] in1;
-logic [15:0] in2;
-logic [1:0] opcode;
-logic [15:0] result;
-logic u, zx, sw;
+logic [15:0] tst_in1;
+logic [15:0] tst_in2;
+logic [1:0] tst_opcode;
+logic [15:0] tst_result;
+logic tst_is_arith_nlogic, tst_zero_x, tst_swap_operands;
alu uut (
- .X(in1),
- .Y(in2),
- .opcode(opcode),
- .RES(result),
- .u(u),
- .zx(zx),
- .sw(sw)
+ .X_in(tst_in1),
+ .Y_in(tst_in2),
+ .opcode_in(tst_opcode),
+ .result_out(tst_result),
+ .u_arith_nlogic_in(tst_is_arith_nlogic),
+ .zx_in(tst_zero_x),
+ .sw_in(tst_swap_operands)
);
string filename;
@@ -31,130 +31,130 @@ initial begin
end
initial begin
- zx = 0;
- sw = 0;
+ tst_zero_x = 0;
+ tst_swap_operands = 0;
// Arith tests
- u = 1;
- in1 = 13;
- in2 = 17;
- opcode = ARITH_PLUS;
+ tst_is_arith_nlogic = 1;
+ tst_in1 = 13;
+ tst_in2 = 17;
+ tst_opcode = ARITH_PLUS;
#1
- assert(result == 30)
- else $error("Expected: 30, got: %d", result);
+ assert(tst_result == 30)
+ else $error("Expected: 30, got: %d", tst_result);
#1
- in1 = 12;
- in2 = 4;
- opcode = ARITH_MINUS;
+ tst_in1 = 12;
+ tst_in2 = 4;
+ tst_opcode = ARITH_MINUS;
#1
- assert(result == 8)
- else $error("Expected: 8, got: %d", result);
+ assert(tst_result == 8)
+ else $error("Expected: 8, got: %d", tst_result);
#1
- in1 = 12;
- in2 = 13;
- opcode = ARITH_MINUS;
+ tst_in1 = 12;
+ tst_in2 = 13;
+ tst_opcode = ARITH_MINUS;
#1
- assert(result == 16'hffff)
- else $error("Expected: 16'hffff, got: %d", result);
+ assert(tst_result == 16'hffff)
+ else $error("Expected: 16'hffff, got: %d", tst_result);
#1
- in1 = 13;
- in2 = 17;
- opcode = ARITH_INC;
+ tst_in1 = 13;
+ tst_in2 = 17;
+ tst_opcode = ARITH_INC;
#1
- assert(result == 14)
- else $error("Expected: 14, got: %d", result);
+ assert(tst_result == 14)
+ else $error("Expected: 14, got: %d", tst_result);
#1
- in1 = 13;
- in2 = 17;
- opcode = ARITH_DEC;
+ tst_in1 = 13;
+ tst_in2 = 17;
+ tst_opcode = ARITH_DEC;
#1
- assert(result == 12)
- else $error("Expected: 12, got: %d", result);
+ assert(tst_result == 12)
+ else $error("Expected: 12, got: %d", tst_result);
#1
- in1 = 0;
- in2 = 17;
- opcode = ARITH_DEC;
+ tst_in1 = 0;
+ tst_in2 = 17;
+ tst_opcode = ARITH_DEC;
#1
- assert(result == 16'hffff)
- else $error("Expected: 16'hffff, got: %d", result);
+ assert(tst_result == 16'hffff)
+ else $error("Expected: 16'hffff, got: %d", tst_result);
#1
// logic tests
- u = 0;
- in1 = 16'b1010;
- in2 = 16'b1100;
- opcode = LOGIC_AND;
+ tst_is_arith_nlogic = 0;
+ tst_in1 = 16'b1010;
+ tst_in2 = 16'b1100;
+ tst_opcode = LOGIC_AND;
#1
- assert(result == 16'b1000)
- else $error("Expected: 16'b1000, got: %d", result);
+ assert(tst_result == 16'b1000)
+ else $error("Expected: 16'b1000, got: %d", tst_result);
#1
- in1 = 16'b1010;
- in2 = 16'b1100;
- opcode = LOGIC_OR;
+ tst_in1 = 16'b1010;
+ tst_in2 = 16'b1100;
+ tst_opcode = LOGIC_OR;
#1
- assert(result == 16'b1110)
- else $error("Expected: 16'b1110, got: %d", result);
+ assert(tst_result == 16'b1110)
+ else $error("Expected: 16'b1110, got: %d", tst_result);
#1
- in1 = 16'b1010;
- in2 = 16'b1100;
- opcode = LOGIC_XOR;
+ tst_in1 = 16'b1010;
+ tst_in2 = 16'b1100;
+ tst_opcode = LOGIC_XOR;
#1
- assert(result == 16'b0110)
- else $error("Expected: 16'b0110, got: %d", result);
+ assert(tst_result == 16'b0110)
+ else $error("Expected: 16'b0110, got: %d", tst_result);
#1
- in1 = 16'b1010101010101010;
- opcode = LOGIC_NEGT;
+ tst_in1 = 16'b1010101010101010;
+ tst_opcode = LOGIC_NEGT;
#1
- assert(result == 16'b0101010101010101)
- else $error("Expected: 16'b0101010101010101, got: %d", result);
+ assert(tst_result == 16'b0101010101010101)
+ else $error("Expected: 16'b0101010101010101, got: %d", tst_result);
#1
// zero - tests
- zx = 1;
- sw = 0;
+ tst_zero_x = 1;
+ tst_swap_operands = 0;
// back to logic
- u = 0;
- in1 = 2;
- in2 = 4;
- opcode = LOGIC_OR;
+ tst_is_arith_nlogic = 0;
+ tst_in1 = 2;
+ tst_in2 = 4;
+ tst_opcode = LOGIC_OR;
#1
- assert(result == 4)
- else $error("Expected 4, got %d", result);
+ assert(tst_result == 4)
+ else $error("Expected 4, got %d", tst_result);
#1
// back to arith
- u = 1;
- in1 = 2;
- in2 = 4;
- opcode = ARITH_PLUS;
+ tst_is_arith_nlogic = 1;
+ tst_in1 = 2;
+ tst_in2 = 4;
+ tst_opcode = ARITH_PLUS;
#1
- assert(result == 4)
- else $error("Expected 4, got %d", result);
+ assert(tst_result == 4)
+ else $error("Expected 4, got %d", tst_result);
#1
// swap tests
- zx = 0;
- sw = 1;
- u = 1;
- in1 = 2;
- in2 = 3;
- opcode = ARITH_MINUS;
+ tst_zero_x = 0;
+ tst_swap_operands = 1;
+ tst_is_arith_nlogic = 1;
+ tst_in1 = 2;
+ tst_in2 = 3;
+ tst_opcode = ARITH_MINUS;
#1
// 3 - 2
- assert(result == 1)
- else $error("Expected 1, got %d", result);
+ assert(tst_result == 1)
+ else $error("Expected 1, got %d", tst_result);
// zero-swap
- zx = 1;
- sw = 1;
- u = 1;
- in1 = 2;
- in2 = 3;
- opcode = ARITH_PLUS;
+ tst_zero_x = 1;
+ tst_swap_operands = 1;
+ tst_is_arith_nlogic = 1;
+ tst_in1 = 2;
+ tst_in2 = 3;
+ tst_opcode = ARITH_PLUS;
#1
// 2 + 0
- assert(result == 2)
- else $error("Expected 2, got %d", result);
+ assert(tst_result == 2)
+ else $error("Expected 2, got %d", tst_result);
$finish();
end