From 55589ea0b0a4287201a618795b4e385d662e9f32 Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Sun, 27 Sep 2020 17:00:21 -0700 Subject: [PATCH] thumb move shifted register (- carry flag) diverges from armwrestler here bc of carry flag --- src/crab/thumb/move_shifted_register.cr | 17 +++++++++++++++++ src/crab/thumb/thumb.cr | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/crab/thumb/move_shifted_register.cr diff --git a/src/crab/thumb/move_shifted_register.cr b/src/crab/thumb/move_shifted_register.cr new file mode 100644 index 0000000..a4e1281 --- /dev/null +++ b/src/crab/thumb/move_shifted_register.cr @@ -0,0 +1,17 @@ +module THUMB + def thumb_move_shifted_register(instr : Word) : Nil + # todo carry flags (currently first divergence on armwrestler) + op = bits(instr, 11..12) + offset = bits(instr, 6..10) + rs = bits(instr, 3..5) + rd = bits(instr, 0..2) + @r[rd] = case op + when 0b00 then @r[rs] << offset + when 0b01 then @r[rs] >> offset + when 0b10 then @r[rs] // (2 ** offset) + else raise "Invalid shifted register op: #{op}" + end + @cpsr.zero = @r[rd] == 0 + @cpsr.negative = bit?(@r[rd], 31) + end +end diff --git a/src/crab/thumb/thumb.cr b/src/crab/thumb/thumb.cr index e05a54b..b0450c1 100644 --- a/src/crab/thumb/thumb.cr +++ b/src/crab/thumb/thumb.cr @@ -43,7 +43,7 @@ module THUMB elsif idx & 0b11111100 == 0b00011000 # add/subtract elsif idx & 0b11100000 == 0b00000000 - # move shifted register + lut[idx] = ->thumb_move_shifted_register(Word) end end lut