def run(state: programState.ProgramState) -> Tuple[programState.ProgramState, Union[programState.RunError, None]]: a, err = state.getReg(arg2) if isinstance(arg3, str): if err is None: b, err = state.getReg(arg3) else: b, _ = state.getReg(arg3) else: b = arg3 & 0XFFFFFFFF minusB = ((~b)+1) & 0xFFFFFFFF out = a + minusB out32 = out & 0xFFFFFFFF bit31 = (out32 >> 31) & 1 signA = (a >> 31) & 1 signB = (minusB >> 31) & 1 v = signA == signB and signB != bit31 c = bool((out >> 32) & 1) n = bool((out >> 31) & 1) z = out32 == 0 state.setReg(arg1, out32) state.setALUState(programState.StatusRegister(n, z, c, v)) return state, err
def run(state: programState.ProgramState) -> Tuple[programState.ProgramState, Union[programState.RunError, None]]: a, err = state.getReg(arg2) if isinstance(arg3, str): if err is None: b, err = state.getReg(arg3) else: b, _ = state.getReg(arg3) if b > 32: return state, programState.RunError(f"Shift value is out of range: value must be below 33 but is {b}", programState.RunError.ErrorType.Error) else: b = arg3 out = a >> b out32 = out & 0xFFFF_FFFF if ((a >> 31) & 1) == 1: # sign-extend out32 |= (0xFFFF_FFFF << (32 - b)) & 0xFFFF_FFFF if b == 0: c = state.status.C # The C flag is unaffected if the shift value is 0 - ARM docs else: c = bool((a >> (b-1)) & 1) # Get last bit shifted out n = bool((out32 >> 31) & 1) z = out32 == 0 state.setReg(arg1, out32) state.setALUState(programState.StatusRegister(n, z, c, False)) return state, err
def run(state: programState.ProgramState) -> Tuple[programState.ProgramState, Union[programState.RunError, None]]: a, err = state.getReg(arg2) if isinstance(arg3, str): if err is None: b, err = state.getReg(arg3) else: b, _ = state.getReg(arg3) else: b = arg3 & 0XFFFFFFFF bMod32 = b & 31 out = (a >> bMod32) | (a << (32 - bMod32)) out32 = out & 0xFFFF_FFFF if b == 0: c = state.status.C # The C flag is unaffected if the shift value is 0 - ARM docs else: c = bool((a >> (bMod32-1)) & 1) # Get last bit shifted out n = bool((out32 >> 31) & 1) z = out32 == 0 state.setReg(arg1, out32) state.setALUState(programState.StatusRegister(n, z, c, False)) return state, err
def run(state: programState.ProgramState) -> Tuple[programState.ProgramState, Union[programState.RunError, None]]: a, err = state.getReg(arg2) if isinstance(arg3, str): if err is None: b, err = state.getReg(arg3) else: b, _ = state.getReg(arg3) else: b = arg3 & 0XFFFFFFFF # subtract one more if carry is set if state.status.C: b += 1 out = a + b out32 = out & 0xFFFFFFFF bit31 = (out32 >> 31) & 1 signA = (a >> 31) & 1 signB = (b >> 31) & 1 v = signA == signB and signB != bit31 c = bool((out >> 32) & 1) n = bool((out >> 31) & 1) z = out32 == 0 state.setReg(arg1, out32) state.setALUState(programState.StatusRegister(n, z, c, v)) return state, err
def run(state: programState.ProgramState) -> Tuple[programState.ProgramState, Union[programState.RunError, None]]: a = state.getReg(arg2) if isinstance(arg3, str): b = state.getReg(arg3) else: b = arg3 # subtract one more if carry is set if state.status.C: b += 1 minusB = ((~b)+1) & 0xFFFFFFFF out = a + minusB out32 = out & 0xFFFFFFFF bit31 = (out32 >> 31) & 1 signA = (a >> 31) & 1 signB = (minusB >> 31) & 1 v = signA == signB and signB != bit31 c = bool((out >> 32) & 1) n = bool((out >> 31) & 1) z = out32 == 0 state.setReg(arg1, out32) state.setALUState(programState.StatusRegister(n, z, c, v)) return state, None
def run(state: programState.ProgramState) -> Tuple[programState.ProgramState, Union[programState.RunError, None]]: a = state.getReg(arg2) b = state.getReg(arg3) out32 = (a * b) & 0xFFFFFFFF n = bool((out32 >> 31) & 1) z = out32 == 0 state.setReg(arg1, out32) state.setALUState(programState.StatusRegister(n, z, state.status.C, state.status.V)) return state, None
def run(state: programState.ProgramState) -> Tuple[programState.ProgramState, Union[programState.RunError, None]]: a = state.getReg(arg1) if isinstance(arg2, str): b = state.getReg(arg2) else: b = arg2 & 0XFFFFFFFF out = a & b n = bool((out >> 31) & 1) z = out == 0 # state.setReg(arg1, out) state.setALUState(programState.StatusRegister(n, z, False, False)) return state, None
def run(state: programState.ProgramState) -> Tuple[programState.ProgramState, Union[programState.RunError, None]]: a, err = state.getReg(arg2) if isinstance(arg3, str): if err is None: b, err = state.getReg(arg3) else: b, _ = state.getReg(arg3) else: b = arg3 & 0XFFFFFFFF out = a & (b ^ 0xFFFF_FFFF) # out = a & ! b n = bool((out >> 31) & 1) z = out == 0 state.setReg(arg1, out) state.setALUState(programState.StatusRegister(n, z, False, False)) return state, err
def run(state: programState.ProgramState) -> Tuple[programState.ProgramState, Union[programState.RunError, None]]: a = state.getReg(arg1) if isinstance(arg2, str): b = state.getReg(arg2) else: b = arg2 & 0XFFFFFFFF out = a + b out32 = out & 0xFFFFFFFF bit31 = (out32 >> 31) & 1 signA = (a >> 31) & 1 signB = (b >> 31) & 1 v = signA == signB and signB != bit31 c = bool((out >> 32) & 1) n = bool((out >> 31) & 1) z = out32 == 0 # state.setReg(arg1, out32) state.setALUState(programState.StatusRegister(n, z, c, v)) return state, None
def run(state: programState.ProgramState) -> Tuple[programState.ProgramState, Union[programState.RunError, None]]: a = state.getReg(arg2) if isinstance(arg3, str): b = state.getReg(arg3) if b > 31: return state, programState.RunError(f"Shift value is out of range: value must be below 32 but is {b}", programState.RunError.ErrorType.Error) else: b = arg3 out = a << b out32 = out & 0xFFFF_FFFF if b == 0: c = state.status.C # The C flag is unaffected if the shift value is 0 - ARM docs else: c = bool((out >> 32) & 1) # Get the last bit shifted out n = bool((out32 >> 31) & 1) z = out32 == 0 state.setReg(arg1, out32) state.setALUState(programState.StatusRegister(n, z, c, False)) return state, None