thumb add/subtract

This commit is contained in:
Matthew Berry 2020-09-27 22:41:02 -07:00
parent 3471a8b34c
commit 0ec726cfbe
2 changed files with 23 additions and 1 deletions

View file

@ -0,0 +1,22 @@
module THUMB
def thumb_add_subtract(instr : Word) : Nil
imm_flag = bit?(instr, 10)
sub = bit?(instr, 9)
imm = bits(instr, 6..8)
rs = bits(instr, 3..5)
rd = bits(instr, 0..2)
operand = if imm_flag
imm
else
@r[imm]
end
if sub
@r[rd] = @r[rs] &- operand
else
@r[rd] = @r[rs] &+ operand
end
# todo handle carry flag on all ops
@cpsr.zero = @r[rd] == 0
@cpsr.negative = bit?(@r[rd], 31)
end
end

View file

@ -41,7 +41,7 @@ module THUMB
elsif idx & 0b11100000 == 0b00100000
lut[idx] = ->thumb_move_compare_add_subtract(Word)
elsif idx & 0b11111100 == 0b00011000
# add/subtract
lut[idx] = ->thumb_add_subtract(Word)
elsif idx & 0b11100000 == 0b00000000
lut[idx] = ->thumb_move_shifted_register(Word)
end