mirror of
https://github.com/mattrberry/crab.git
synced 2025-01-29 20:35:13 +01:00
set proper flags for adc
This commit is contained in:
parent
ad446281fc
commit
3d0408d702
2 changed files with 14 additions and 1 deletions
|
@ -138,6 +138,19 @@ class CPU
|
|||
res
|
||||
end
|
||||
|
||||
# Add two values with carry
|
||||
def adc(operand_1 : Word, operand_2 : Word, set_conditions) : Word
|
||||
log "adc - operand_1:#{hex_str operand_1}, operand_2:#{hex_str operand_2}"
|
||||
res = operand_1 &+ operand_2 &+ @cpsr.carry.to_unsafe
|
||||
if set_conditions
|
||||
@cpsr.overflow = bit?(~(operand_1 ^ operand_2) & (operand_2 ^ res), 31)
|
||||
@cpsr.carry = res < operand_1
|
||||
@cpsr.zero = res == 0
|
||||
@cpsr.negative = bit?(res, 31)
|
||||
end
|
||||
res
|
||||
end
|
||||
|
||||
def print_state(instr : Word) : Nil
|
||||
{% if flag? :trace %}
|
||||
@r.each do |reg|
|
||||
|
|
|
@ -10,7 +10,7 @@ module THUMB
|
|||
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 0b0101 then res = @r[rd] = adc(@r[rd], @r[rs], true)
|
||||
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]
|
||||
|
|
Loading…
Add table
Reference in a new issue