aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--tclasm.tcl52
-rwxr-xr-xtests/stack_machine_multiinstructions_load_store/instructions.s.tcl54
l---------tests/stack_machine_multiinstructions_load_store/test.v1
-rw-r--r--tests/stack_machine_multiinstructions_load_store/words_to_verify.mem12
5 files changed, 119 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 59ec377..5993ca6 100644
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,8 @@ STACK_MACHINE_OLD_TESTS := \
STACK_MACHINE_TESTS := \
store \
- load_store
+ load_store \
+ multiinstructions_load_store
# Add other tests here if You need
TESTS := \
diff --git a/tclasm.tcl b/tclasm.tcl
index e552b4d..fd45456 100644
--- a/tclasm.tcl
+++ b/tclasm.tcl
@@ -64,30 +64,78 @@ proc _im {value} {
puts 1[__to_binary $value 15]
}
-proc _const {value} {
- puts 010100000[__to_binary $value 7]
+proc _with_im {command number} {
+
+ set value [expr [__parse_number $number] + 0]
+ if {$value < 2 ** 6 && $value >= -(2 ** 6)} {
+ $command $value
+ } elseif {$value < 2 ** 21 && $value >= -(2 ** 21)} {
+ _im [expr $value >> 7]
+ $command [expr $value & 0x7F]
+ } elseif {$value < 2 ** 32 && $value >= -(2 ** 31)} {
+ _im [expr $value >> 22]
+ _im [expr ($value >> 7) & 0x7FFF]
+ $command [expr $value & 0x7F]
+ } else {
+ error "number '$number' doesn't fit in 32 bits"
+ }
+}
+
+
+proc _const {value_part} {
+ puts 010100000[__to_binary $value_part 7]
+}
+
+proc const {value} {
+ _with_im _const $value
}
+
proc _store {address_part} {
puts 011111100[__to_binary $address_part 7]
}
+proc store {address} {
+ _with_im _store $address
+}
+
+
proc _store+ {address_part} {
puts 011011100[__to_binary $address_part 7]
}
+proc store+ {address} {
+ _with_im _store+ $address
+}
+
+
proc _load {address_part} {
puts 010111100[__to_binary $address_part 7]
}
+proc load {address} {
+ _with_im _load $address
+}
+
+
proc _load+ {address_part} {
puts 010011100[__to_binary $address_part 7]
}
+proc load+ {address} {
+ _with_im _load+ $address
+}
+
+
proc _set_sp {address_part} {
puts 010000000[__to_binary $address_part 7]
}
+proc set_sp {address} {
+ _with_im _set_sp $address
+}
+
+
proc halt {} {
puts 0000000000000000
}
diff --git a/tests/stack_machine_multiinstructions_load_store/instructions.s.tcl b/tests/stack_machine_multiinstructions_load_store/instructions.s.tcl
new file mode 100755
index 0000000..bd16f8a
--- /dev/null
+++ b/tests/stack_machine_multiinstructions_load_store/instructions.s.tcl
@@ -0,0 +1,54 @@
+#!/usr/bin/env tclsh
+
+source tclasm.tcl
+
+### set stack to h1FFE00, store 4 numbers (h11223344, h55667788, h8899AABB and
+### hCCDDEEFF) at addresses h00002E, h00003E, h00004E and h00005E and load them
+### back to stack (only 2 will really get written to stack's memory, other 2
+### will remain in r0 and r1). Then, write them to h00F0F0, h08F0F0, h10F0F0 and
+### h18F0F0.
+### At the and use operand-addressing to load back value h55667788 from h00003E
+### (expressed as h000040 in im + (-2) in operand) and store it to h1FFFCD
+### (expressed as h1F0F0D in im + h00F0C0 in operand).
+
+## set up stack
+set_sp 0
+
+## get number h11223344 into r1, and store it - repeat for other 3 numbers;
+const h11223344
+store h00002E
+
+const h55667788
+store h00003E
+
+const h8899AABB
+store h00004E
+
+const hCCDDEEFF
+store h00005E
+
+## get numbers back on stack
+load h00002E
+load h00003E
+load h00004E
+load h00005E
+
+## store copies to new locations
+store h18F0F0
+store h10F0F0
+store h08F0F0
+store h00F0F0
+
+## prepare operand for later store operation
+const h00F0C0
+
+## use operand addressing to load back value from h000018
+const -2
+load+ h000040
+
+## use operand addressing to trove value to h1FFFE2 = h1FFFC0 + h000022
+# immediate value gets sign-extended here!
+store+ h1F0F0D
+
+## finish test
+halt
diff --git a/tests/stack_machine_multiinstructions_load_store/test.v b/tests/stack_machine_multiinstructions_load_store/test.v
new file mode 120000
index 0000000..f5b6a59
--- /dev/null
+++ b/tests/stack_machine_multiinstructions_load_store/test.v
@@ -0,0 +1 @@
+../stack_machine_store/test.v \ No newline at end of file
diff --git a/tests/stack_machine_multiinstructions_load_store/words_to_verify.mem b/tests/stack_machine_multiinstructions_load_store/words_to_verify.mem
new file mode 100644
index 0000000..14b6f32
--- /dev/null
+++ b/tests/stack_machine_multiinstructions_load_store/words_to_verify.mem
@@ -0,0 +1,12 @@
+// address value
+ 2E 11223344
+ 3E 55667788
+ 4E 8899AABB
+ 5E CCDDEEFF
+
+ 00F0F0 11223344
+ 08F0F0 55667788
+ 10F0F0 8899AABB
+ 18F0F0 CCDDEEFF
+
+ 1FFFCD 55667788