bugmeout / pyemu

Automatically exported from code.google.com/p/pyemu
0 stars 0 forks source link

0x2 ADD (r8 += r/m8) is missing #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
PyCPU lacks support for the 0x2 ADD instruction, resulting in execute() to 
fail for asm commands like:

add     al, byte-ptr[edi+edx]

Adding the following lines to def ADD(self, instruction) in PyCPU.py fixed 
the issue for me:

#02 r8 ADD r/m8 Add r/m8 to r8
        elif instruction.opcode == 0x02:
            osize = 1
            op1value = self.get_register(op1.reg, osize)

            if op2.type == pydasm.OPERAND_TYPE_REGISTER:
                op2value = self.get_register(op2.reg, osize)

                # Do logic
                result = op1value + op2value

                self.set_flags("ADD", op1value, op2value, result, osize)

                result = self.sanitize_value(result, osize)

                self.set_register(op1.reg, result, osize)

            elif op2.type == pydasm.OPERAND_TYPE_MEMORY:
                op2value = self.get_memory_address(instruction, 1, asize)

                # Do logic
                op2valuederef = self.get_memory(op2value, osize)

                result = op1value + op2valuederef

                self.set_flags("ADD", op1value, op2valuederef, result, 
osize)

                result = self.sanitize_value(result, osize)

                self.set_register(op1.reg, result, osize)

Original issue reported on code.google.com by mee...@trash-mail.com on 24 May 2010 at 5:32