aboutsummaryrefslogtreecommitdiff
path: root/tclasm.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'tclasm.tcl')
-rw-r--r--tclasm.tcl52
1 files changed, 50 insertions, 2 deletions
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
}