mirror of
https://github.com/mattrberry/crab.git
synced 2024-12-31 10:23:42 +01:00
thumb alu operations
This commit is contained in:
parent
7820e69eb6
commit
ac7e3bbe72
2 changed files with 29 additions and 1 deletions
28
src/crab/thumb/alu_operations.cr
Normal file
28
src/crab/thumb/alu_operations.cr
Normal file
|
@ -0,0 +1,28 @@
|
|||
module THUMB
|
||||
def thumb_alu_operations(instr : Word) : Nil
|
||||
op = bits(instr, 6..9)
|
||||
rs = bits(instr, 3..5)
|
||||
rd = bits(instr, 0..2)
|
||||
case op
|
||||
when 0b0000 then res = @r[rd] = @r[rd] & @r[rs]
|
||||
when 0b0001 then res = @r[rd] = @r[rd] ^ @r[rs]
|
||||
when 0b0010 then res = @r[rd] = lsl(@r[rd], @r[rs], true)
|
||||
when 0b0011 then res = @r[rd] = lsr(@r[rd], @r[rs], true)
|
||||
when 0b0100 then res = @r[rd] = asr(@r[rd], @r[rs], true)
|
||||
when 0b0101 then res = @r[rd] = @r[rd] &+ @r[rs] &+ @cpsr.carry.to_unsafe
|
||||
when 0b0110 then res = @r[rd] = @r[rd] &- @r[rs] &- ~@cpsr.carry.to_unsafe
|
||||
when 0b0111 then res = @r[rd] = ror(@r[rd], @r[rs], true)
|
||||
when 0b1000 then res = @r[rd] & @r[rs]
|
||||
when 0b1001 then res = @r[rd] = (-@r[rs].to_i32!).to_u32!
|
||||
when 0b1010 then res = @r[rd] &- @r[rs]
|
||||
when 0b1011 then res = @r[rd] &+ @r[rs]
|
||||
when 0b1100 then res = @r[rd] = @r[rd] | @r[rs]
|
||||
when 0b1101 then res = @r[rd] = @r[rs] * @r[rd]
|
||||
when 0b1110 then res = @r[rd] = @r[rd] & ~@r[rs]
|
||||
when 0b1111 then res = @r[rd] = ~@r[rs]
|
||||
else raise "Invalid alu op: #{op}"
|
||||
end
|
||||
@cpsr.zero = res == 0
|
||||
@cpsr.negative = bit?(res, 31)
|
||||
end
|
||||
end
|
|
@ -37,7 +37,7 @@ module THUMB
|
|||
elsif idx & 0b11111100 == 0b01000100
|
||||
# hi register operations / branch exchange
|
||||
elsif idx & 0b11111100 == 0b01000000
|
||||
# alu operations
|
||||
lut[idx] = ->thumb_alu_operations(Word)
|
||||
elsif idx & 0b11100000 == 0b00100000
|
||||
lut[idx] = ->thumb_move_compare_add_subtract(Word)
|
||||
elsif idx & 0b11111100 == 0b00011000
|
||||
|
|
Loading…
Reference in a new issue