diff options
author | Wojciech Kosior <kwojtus@protonmail.com> | 2020-09-05 14:47:13 +0200 |
---|---|---|
committer | Wojciech Kosior <kwojtus@protonmail.com> | 2020-09-05 14:47:13 +0200 |
commit | 6295bacd000e00d7c569fdc64697a29561f1d2b1 (patch) | |
tree | 70355a4e0a163bd53d01790704bd5fc40b8adf7e /tclasm.tcl | |
parent | 67338780099d1384b36623780a5a63c3be5ade9d (diff) | |
download | AGH-engineering-thesis-6295bacd000e00d7c569fdc64697a29561f1d2b1.tar.gz AGH-engineering-thesis-6295bacd000e00d7c569fdc64697a29561f1d2b1.zip |
add tclasm multiinstructions (instructions, that possibly translate to more than one)
Diffstat (limited to 'tclasm.tcl')
-rw-r--r-- | tclasm.tcl | 52 |
1 files changed, 50 insertions, 2 deletions
@@ -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 } |