From 92206c93690c5658928c9f8b1324e1a455e1a453 Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Sat, 5 Sep 2020 18:57:00 +0200 Subject: add cond_jump instruction together with bench --- Makefile | 3 +- design/stack_machine.v | 11 ++++++++ tclasm.tcl | 9 ++++++ tests/stack_machine_cond_jump/instructions.s.tcl | 34 +++++++++++++++++++++++ tests/stack_machine_cond_jump/test.v | 1 + tests/stack_machine_cond_jump/words_to_verify.mem | 6 ++++ 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100755 tests/stack_machine_cond_jump/instructions.s.tcl create mode 120000 tests/stack_machine_cond_jump/test.v create mode 100644 tests/stack_machine_cond_jump/words_to_verify.mem diff --git a/Makefile b/Makefile index 454b499..73a6aff 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,8 @@ STACK_MACHINE_TESTS := \ sub \ div \ mul \ - jump + jump \ + cond_jump # Add other tests here if You need TESTS := \ diff --git a/design/stack_machine.v b/design/stack_machine.v index 150f6c7..b6c2706 100644 --- a/design/stack_machine.v +++ b/design/stack_machine.v @@ -220,6 +220,10 @@ module stack_machine_new assign instr_mul = !set_im && !use_im && stack_shrinks_by_1 && instruction[11:0] == 12'd3; + wire instr_cond_jump; + assign instr_cond_jump = use_im && stack_shrinks_by_1 && + instruction[11:7] == 5'd1; + reg halt; /* Set once a halt instruction is encountered */ assign finished = halt; @@ -519,6 +523,13 @@ module stack_machine_new if (instr_mul && arithmetic_uncompleted) r1 <= r0 * r1; + + if (instr_cond_jump && arithmetic_uncompleted) begin + r1 <= r0; + + if (r1) + `SET_PC(im_effective); + end end // case: STEP_EXECUTING endcase // case (step) end // else: !if(RST_I) diff --git a/tclasm.tcl b/tclasm.tcl index 1f716ee..cafe99f 100644 --- a/tclasm.tcl +++ b/tclasm.tcl @@ -195,3 +195,12 @@ proc div {} { proc mul {} { puts 0011000000000011 } + + +proc _cond_jump {address_part} { + puts 011100001[__to_binary $address_part 7] +} + +proc cond_jump {address} { + _with_im _cond_jump $address +} diff --git a/tests/stack_machine_cond_jump/instructions.s.tcl b/tests/stack_machine_cond_jump/instructions.s.tcl new file mode 100755 index 0000000..d1d5809 --- /dev/null +++ b/tests/stack_machine_cond_jump/instructions.s.tcl @@ -0,0 +1,34 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +## also look at stack_machine_jump test + +## we're going to write numbers from 0 to 7 to addresses h400 - h41C + +# this will translate to 1 16-bit instruction +set_sp 0 + +## set up the counter (1 16-bit instruction) +const 0 + +## this is the point we later jump to, address 4 +tee +tee +## compute address: counter * 4 + h400 and save counter to it +const 4 +mul +swap +store+ h400 + +## increase counter by 1 +const 1 +add +## compare value of counter to 8 +tee +const 8 +sub +## loop if counter != 8 +cond_jump 4 + +halt diff --git a/tests/stack_machine_cond_jump/test.v b/tests/stack_machine_cond_jump/test.v new file mode 120000 index 0000000..f5b6a59 --- /dev/null +++ b/tests/stack_machine_cond_jump/test.v @@ -0,0 +1 @@ +../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_cond_jump/words_to_verify.mem b/tests/stack_machine_cond_jump/words_to_verify.mem new file mode 100644 index 0000000..aa047b5 --- /dev/null +++ b/tests/stack_machine_cond_jump/words_to_verify.mem @@ -0,0 +1,6 @@ +// address value + 00400 0 // verify the first number written + + 00408 2 // verify a number in the middle + + 0041C 7 // verify the last number -- cgit v1.2.3