From 6295bacd000e00d7c569fdc64697a29561f1d2b1 Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Sat, 5 Sep 2020 14:47:13 +0200 Subject: add tclasm multiinstructions (instructions, that possibly translate to more than one) --- tclasm.tcl | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'tclasm.tcl') 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 } -- cgit v1.2.3