mirror of
https://github.com/mattrberry/crab.git
synced 2025-02-06 08:45:53 +01:00
thumb add/subtract
This commit is contained in:
parent
3471a8b34c
commit
0ec726cfbe
2 changed files with 23 additions and 1 deletions
22
src/crab/thumb/add_subtract.cr
Normal file
22
src/crab/thumb/add_subtract.cr
Normal 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
|
|
@ -41,7 +41,7 @@ module THUMB
|
||||||
elsif idx & 0b11100000 == 0b00100000
|
elsif idx & 0b11100000 == 0b00100000
|
||||||
lut[idx] = ->thumb_move_compare_add_subtract(Word)
|
lut[idx] = ->thumb_move_compare_add_subtract(Word)
|
||||||
elsif idx & 0b11111100 == 0b00011000
|
elsif idx & 0b11111100 == 0b00011000
|
||||||
# add/subtract
|
lut[idx] = ->thumb_add_subtract(Word)
|
||||||
elsif idx & 0b11100000 == 0b00000000
|
elsif idx & 0b11100000 == 0b00000000
|
||||||
lut[idx] = ->thumb_move_shifted_register(Word)
|
lut[idx] = ->thumb_move_shifted_register(Word)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue