def execute_cmp(s, inst): if condition_passed(s, inst.cond()): a, (b, _) = s.rf[inst.rn()], shifter_operand(s, inst) result = a - b s.N = (result >> 31) & 1 s.Z = trim_32(result) == 0 s.C = not borrow_from(result) s.V = overflow_from_sub(a, b, result) if inst.rd() == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_tst(s, inst): if condition_passed(s, inst.cond()): a, (b, cout) = s.rf[inst.rn()], shifter_operand(s, inst) result = trim_32(a & b) if inst.S(): s.N = (result >> 31) & 1 s.Z = result == 0 s.C = cout if inst.rd() == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_cmp( s, inst ): if condition_passed( s, inst.cond ): a, (b, _) = s.rf[ inst.rn ], shifter_operand( s, inst ) result = intmask( a - b ) s.N = (result >> 31)&1 s.Z = trim_32( result ) == 0 s.C = not_borrow_from( result ) s.V = overflow_from_sub( a, b, result ) if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_cmn( s, inst ): if condition_passed( s, inst.cond ): a, (b, _) = s.rf[ inst.rn ], shifter_operand( s, inst ) result = a + b s.N = (result >> 31)&1 s.Z = trim_32( result ) == 0 s.C = carry_from( result ) s.V = overflow_from_add( a, b, result ) if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_cmn(s, inst): if condition_passed(s, inst.cond): a, (b, _) = s.rf[inst.rn], shifter_operand(s, inst) result = a + b s.N = (result >> 31) & 1 s.Z = trim_32(result) == 0 s.C = carry_from(result) s.V = overflow_from_add(a, b, result) if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_tst( s, inst ): if condition_passed( s, inst.cond ): a, (b, cout) = s.rf[ inst.rn ], shifter_operand( s, inst ) result = trim_32( a & b ) if inst.S: s.N = (result >> 31)&1 s.Z = result == 0 s.C = cout if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_bic( s, inst ): if condition_passed( s, inst.cond ): a, (b, cout) = s.rf[ inst.rn ], shifter_operand( s, inst ) result = a & trim_32(~b) s.rf[ inst.rd ] = trim_32( result ) if inst.S: if inst.rd == 15: raise FatalError('Writing SPSR not implemented!') s.N = (result >> 31)&1 s.Z = trim_32( result ) == 0 s.C = cout if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_bic(s, inst): if condition_passed(s, inst.cond): a, (b, cout) = s.rf[inst.rn], shifter_operand(s, inst) result = a & trim_32(~b) s.rf[inst.rd] = trim_32(result) if inst.S: if inst.rd == 15: raise FatalError('Writing SPSR not implemented!') s.N = (result >> 31) & 1 s.Z = trim_32(result) == 0 s.C = cout if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_mvn( s, inst ): if condition_passed( s, inst.cond ): a, cout = shifter_operand( s, inst ) result = trim_32( ~a ) s.rf[ inst.rd ] = result if inst.S: if inst.rd == 15: raise FatalError('Writing SPSR not implemented!') s.N = (result >> 31)&1 s.Z = trim_32( result ) == 0 s.C = cout s.V = s.V if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_sbc(s, inst): if condition_passed(s, inst.cond): a, (b, _) = s.rf[inst.rn], shifter_operand(s, inst) result = intmask(a - b - (not s.C)) s.rf[inst.rd] = trim_32(result) if inst.S: if inst.rd == 15: raise FatalError('Writing SPSR not implemented!') s.N = (result >> 31) & 1 s.Z = trim_32(result) == 0 s.C = not_borrow_from(result) s.V = overflow_from_sub(a, b, result) if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_mvn(s, inst): if condition_passed(s, inst.cond): a, cout = shifter_operand(s, inst) result = trim_32(~a) s.rf[inst.rd] = result if inst.S: if inst.rd == 15: raise FatalError('Writing SPSR not implemented!') s.N = (result >> 31) & 1 s.Z = trim_32(result) == 0 s.C = cout s.V = s.V if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_sbc( s, inst ): if condition_passed( s, inst.cond ): a, (b, _) = s.rf[ inst.rn ], shifter_operand( s, inst ) result = intmask( a - b - (not s.C) ) s.rf[ inst.rd ] = trim_32( result ) if inst.S: if inst.rd == 15: raise FatalError('Writing SPSR not implemented!') s.N = (result >> 31)&1 s.Z = trim_32( result ) == 0 s.C = not_borrow_from( result ) s.V = overflow_from_sub( a, b, result ) if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_adc( s, inst ): if condition_passed( s, inst.cond ): a, (b, _) = s.rf[ inst.rn ], shifter_operand( s, inst ) result = a + b + s.C s.rf[ inst.rd ] = trim_32( result ) if inst.S: if inst.rd == 15: raise FatalError('Writing SPSR not implemented!') s.N = (result >> 31)&1 s.Z = trim_32( result ) == 0 s.C = carry_from( result ) s.V = overflow_from_add( a, b, result ) if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_adc(s, inst): if condition_passed(s, inst.cond): a, (b, _) = s.rf[inst.rn], shifter_operand(s, inst) result = a + b + s.C s.rf[inst.rd] = trim_32(result) if inst.S: if inst.rd == 15: raise FatalError('Writing SPSR not implemented!') s.N = (result >> 31) & 1 s.Z = trim_32(result) == 0 s.C = carry_from(result) s.V = overflow_from_add(a, b, result) if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_rsc(s, inst): if condition_passed(s, inst.cond()): a, (b, _) = s.rf[inst.rn()], shifter_operand(s, inst) result = b - a - (not s.C) s.rf[inst.rd()] = trim_32(result) if inst.S(): if inst.rd() == 15: raise FatalError('Writing SPSR not implemented!') s.N = (result >> 31) & 1 s.Z = trim_32(result) == 0 s.C = not borrow_from(result) s.V = overflow_from_sub(b, a, result) if inst.rd() == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_orr(s, inst): if condition_passed(s, inst.cond()): a, (b, cout) = s.rf[inst.rn()], shifter_operand(s, inst) result = a | b s.rf[inst.rd()] = trim_32(result) if inst.S(): if inst.rd() == 15: raise FatalError('Writing SPSR not implemented!') s.N = (result >> 31) & 1 s.Z = trim_32(result) == 0 s.C = cout s.V = s.V if inst.rd() == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_mov(s, inst): if condition_passed(s, inst.cond()): if inst.rd() == 15 and inst.S(): # if not CurrentModeHasSPSR(): CPSR = SPSR # else: UNPREDICTABLE raise FatalError('UNPREDICTABLE in user and system mode!') result, cout = shifter_operand(s, inst) s.rf[inst.rd()] = trim_32(result) if inst.S(): s.N = (result >> 31) & 1 s.Z = trim_32(result) == 0 s.C = cout s.V = s.V if inst.rd() == 15: return s.rf[PC] = s.fetch_pc() + 4
def execute_mov( s, inst ): if condition_passed( s, inst.cond ): if inst.rd == 15 and inst.S: # if not CurrentModeHasSPSR(): CPSR = SPSR # else: UNPREDICTABLE raise FatalError('UNPREDICTABLE in user and system mode!') result, cout = shifter_operand( s, inst ) s.rf[ inst.rd ] = trim_32( result ) if inst.S: s.N = (result >> 31)&1 s.Z = trim_32( result ) == 0 s.C = cout s.V = s.V if inst.rd == 15: return s.rf[PC] = s.fetch_pc() + 4