Hi Atif,

In target-i386/translate.c, there are many variants of mov i.e.
 case 0x89: /* mov Gv, Ev */
 case 0xc7: /* mov Ev, Iv */
 case 0x8b: /* mov Ev, Gv */
 case 0x8e: /* mov seg, Gv */


That's true. I forgot the fact that mov %eax,%eax can be both:

0x89 0xC0
0x8B 0xC0

It's up to the compiler to choose which one to use.

which one do you think will be called when "mov %eax, %eax" instruction is
translated.
I printed the value of modrm inside the case 0x89 but the value remains
the same whether I use %eax or %ebx.

Secondly, How can I extract the source and destination registers from
modrm.


modrm is the byte following the 0x89 or 0x8B opcode. After

modrm = ldub_code(s->pc++);

you can decode it this way (in binary):
XXYYYZZZ

XX --> Indexing mode
YYY --> Destination register
ZZZ --> Source register

0xC0 is the value you are looking for 11 000 000 --> (no
indexing)(%eax)(%eax).

You can find more information here:
http://pdos.csail.mit.edu/6.828/2005/readings/i386/s17_02.htm

One more thing: you may want to check operand size. It's on "ot" variable,
and its meaning (from translate.c):
enum {
   OT_BYTE = 0,
   OT_WORD,
   OT_LONG,
   OT_QUAD,
};

being 8, 16, 32 and 64 bits respectively.

Regards,
Eduardo

Reply via email to