From 5b1aee887b7a9dddbecf40d8afb8e1873ee02331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergiusz=20=27q3k=27=20Baza=C5=84ski?= Date: Sat, 4 Jan 2014 14:07:57 +0100 Subject: [PATCH] All ALU tests pass --- .gitignore | 1 + Makefile | 2 +- cpu.v | 7 +++++-- test_main.cpp | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1377554..4888c89 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.swp +obj_dir diff --git a/Makefile b/Makefile index 63fb6dc..f9295d3 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ obj_dir/Vcpu.cpp: cpu.v test_main.cpp verilator -Wall -cc cpu.v --exe test_main.cpp -obj_dir/Vcpu: obj_dir/Vcpu.cpp +obj_dir/Vcpu: obj_dir/Vcpu.cpp test_main.cpp cd obj_dir; make -j -f Vcpu.mk Vcpu test: obj_dir/Vcpu diff --git a/cpu.v b/cpu.v index f64538f..97cfcbe 100644 --- a/cpu.v +++ b/cpu.v @@ -187,8 +187,11 @@ module cpu ( vr[15] <= {7'b0, vr[x][0]}; vr[x] <= vr[x] >> 1; end - 7: { vr[15], vr[x] } <= ({8'b0, vr[y]} - {8'b0, vr[x]}) ^ (1 << 8); - 15: begin + 7: begin + vr[x] <= vr[y] - vr[x]; + vr[15] <= {7'b0, vr[y] >= vr[x]}; + end + 14: begin vr[15] <= {7'b0, vr[x][7]}; vr[x] <= vr[x] << 1; end diff --git a/test_main.cpp b/test_main.cpp index 7963f4e..82e1a78 100644 --- a/test_main.cpp +++ b/test_main.cpp @@ -99,4 +99,21 @@ int main(int argc, char **argv) test_alu_instruction_vf(0x45, 0x45, 0x8125, 0x00, 0x01); printf("SUB (borrow) "); test_alu_instruction_vf(0x15, 0x45, 0x8125, 0xD0, 0x00); + // SHR + printf("SHR (one) "); + test_alu_instruction_vf(0x45, 0x00, 0x8126, 0x45>>1, 0x01); + printf("SHR (zero) "); + test_alu_instruction_vf(0x44, 0x00, 0x8126, 0x44>>1, 0x00); + // SUBN + printf("SUBN (no borrow) "); + test_alu_instruction_vf(0x15, 0x45, 0x8127, 0x30, 0x01); + printf("SUBN (zero, no borrow) "); + test_alu_instruction_vf(0x45, 0x45, 0x8127, 0x00, 0x01); + printf("SUBN (borrow) "); + test_alu_instruction_vf(0x45, 0x15, 0x8127, 0xD0, 0x00); + // SHL + printf("SHL (one) "); + test_alu_instruction_vf(0xA4, 0x00, 0x812E, (0xA4<<1)&0xFF, 0x01); + printf("SHL (zero) "); + test_alu_instruction_vf(0x24, 0x00, 0x812E, (0x24<<1)&0xFF, 0x00); }