From 3ec21a949b0887e32bbffcdb38a5738abfe8cfd0 Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Sat, 5 Sep 2020 16:58:33 +0200 Subject: add add instruction together with bench --- Makefile | 3 ++- design/stack_machine.v | 28 +++++++++++++++++++++------- tclasm.tcl | 5 +++++ tests/stack_machine_add/instructions.s.tcl | 23 +++++++++++++++++++++++ tests/stack_machine_add/test.v | 1 + tests/stack_machine_add/words_to_verify.mem | 6 ++++++ 6 files changed, 58 insertions(+), 8 deletions(-) create mode 100755 tests/stack_machine_add/instructions.s.tcl create mode 120000 tests/stack_machine_add/test.v create mode 100644 tests/stack_machine_add/words_to_verify.mem diff --git a/Makefile b/Makefile index 8f4e729..6f2227f 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,8 @@ STACK_MACHINE_TESTS := \ store \ load_store \ multiinstructions_load_store \ - tee + tee \ + add # Add other tests here if You need TESTS := \ diff --git a/design/stack_machine.v b/design/stack_machine.v index 04b1285..d79a136 100644 --- a/design/stack_machine.v +++ b/design/stack_machine.v @@ -118,6 +118,9 @@ module stack_machine_new wire stack_shrinks; assign stack_shrinks = instruction[13] == 1'b1 && !set_im; + wire stack_shrinks_by_1; + assign stack_shrinks_by_1 = stack_shrinks && instruction[12] == 1'b1; + wire stack_shrinks_by_2; assign stack_shrinks_by_2 = stack_shrinks && instruction[12] == 1'b0; @@ -193,7 +196,9 @@ module stack_machine_new instruction[11:7] == 5'd0; /* Instructions, that shrink stack */ - /* none now */ + wire instr_add; + assign instr_add = !set_im && !use_im && stack_shrinks_by_1 && + instruction[11:0] == 12'd0; reg halt; /* Set once a halt instruction is encountered */ assign finished = halt; @@ -279,9 +284,6 @@ module stack_machine_new STEP_EXECUTING : begin first_execution_tick <= 0; - if (instr_halt) - halt <= 1; - if (((stack_grows || stack_shrinks || load || store) && first_execution_tick) || (load_store_uncompleted && @@ -425,14 +427,26 @@ module stack_machine_new else im <= 32'bx; - if (instr_const && first_execution_tick) - r1 <= im_effective; + /* Instructions, that do not change stack size */ + if (instr_halt) + halt <= 1; - if (instr_tee) + if (instr_nop) r1 <= r1; if (instr_set_sp) `SET_SP(im_effective); + + /* Instructions, that grow stack */ + if (instr_tee) + r1 <= r1; + + if (instr_const && first_execution_tick) + r1 <= im_effective; + + /* Instructions, that shrink stack */ + if (instr_add && first_execution_tick) + r1 <= r1 + r0; end // case: STEP_EXECUTING endcase // case (step) end // else: !if(RST_I) diff --git a/tclasm.tcl b/tclasm.tcl index c00fe18..f5646a2 100644 --- a/tclasm.tcl +++ b/tclasm.tcl @@ -96,6 +96,11 @@ proc tee {} { } +proc add {} { + puts 0011000000000000 +} + + proc _store {address_part} { puts 011111100[__to_binary $address_part 7] } diff --git a/tests/stack_machine_add/instructions.s.tcl b/tests/stack_machine_add/instructions.s.tcl new file mode 100755 index 0000000..c0a9449 --- /dev/null +++ b/tests/stack_machine_add/instructions.s.tcl @@ -0,0 +1,23 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +### store 2 values to memory, load them back, add them and store the result + +set_sp 0 + +const 12345678 +store h1EEE0 +const 40302010 +store h1EEE4 + +const 8 + +load h1EEE0 +load h1EEE4 +# adding 40302010 to 12345678 should yield 52647688 +add +# will write to h1EEE0 + 8 = h1EEE8 +store+ h1EEE0 + +halt diff --git a/tests/stack_machine_add/test.v b/tests/stack_machine_add/test.v new file mode 120000 index 0000000..f5b6a59 --- /dev/null +++ b/tests/stack_machine_add/test.v @@ -0,0 +1 @@ +../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_add/words_to_verify.mem b/tests/stack_machine_add/words_to_verify.mem new file mode 100644 index 0000000..601e8fd --- /dev/null +++ b/tests/stack_machine_add/words_to_verify.mem @@ -0,0 +1,6 @@ +// address value + 1EEE0 BC614E // 12345678 in hex is BC614E + + 1EEE4 266F5BA // 40302010 in hex is 266F5BA + + 1EEE8 3235708 // 52647688 in hex is 3235708 -- cgit v1.2.3