コード例 #1
0
    def __signed_div(self, oprnd0, oprnd1, result_size):
        op0_val = self.read_operand(oprnd0)
        op1_val = self.read_operand(oprnd1)

        op0_sign = op0_val >> oprnd0.size-1
        op1_sign = op1_val >> oprnd1.size-1
        result_sign = op0_sign ^ op1_sign

        if op0_sign == 0x1:
            op0_tmp = twos_complement(op0_val, oprnd0.size)
        else:
            op0_tmp = op0_val

        if op1_sign == 0x1:
            op1_tmp = twos_complement(op1_val, oprnd1.size)
        else:
            op1_tmp = op1_val

        result_tmp = op0_tmp / op1_tmp

        if result_sign == 0x1:
            result = twos_complement(result_tmp, result_size)
        else:
            result = result_tmp

        return result & (2**result_size-1)
コード例 #2
0
    def __signed_div(self, oprnd0, oprnd1, result_size):
        op0_val = self.read_operand(oprnd0)
        op1_val = self.read_operand(oprnd1)

        op0_sign = op0_val >> oprnd0.size - 1
        op1_sign = op1_val >> oprnd1.size - 1
        result_sign = op0_sign ^ op1_sign

        if op0_sign == 0x1:
            op0_tmp = twos_complement(op0_val, oprnd0.size)
        else:
            op0_tmp = op0_val

        if op1_sign == 0x1:
            op1_tmp = twos_complement(op1_val, oprnd1.size)
        else:
            op1_tmp = op1_val

        result_tmp = op0_tmp / op1_tmp

        if result_sign == 0x1:
            result = twos_complement(result_tmp, result_size)
        else:
            result = result_tmp

        return result & (2**result_size - 1)
コード例 #3
0
    def __execute_bsh(self, instr):
        """Execute BSH instruction.
        """
        op0_val = self.read_operand(instr.operands[0])
        op1_val = self.read_operand(instr.operands[1])

        op1_size = instr.operands[1].size

        # Check sign bit.
        if extract_sign_bit(op1_val, op1_size) == 0:
            op2_val = op0_val << op1_val
        else:
            op2_val = op0_val >> twos_complement(op1_val, op1_size)

        self.write_operand(instr.operands[2], op2_val)

        return None
コード例 #4
0
    def __execute_bsh(self, instr):
        """Execute BSH instruction.
        """
        op0_val = self.read_operand(instr.operands[0])
        op1_val = self.read_operand(instr.operands[1])

        op1_size = instr.operands[1].size

        # Check sign bit.
        if extract_sign_bit(op1_val, op1_size) == 0:
            op2_val = op0_val << op1_val
        else:
            op2_val = op0_val >> twos_complement(op1_val, op1_size)

        self.write_operand(instr.operands[2], op2_val)

        return None