In my quest of writing a small disassembler for linux specific to x86 arch, I'm faced with a small issue. It's with regard to mandatory prefixes and repeat prefixes. Looking at the Intel docs [1], it's said that repeat prefixes are 0xf2 or 0xf3, and mandatory prefixes are 0x66, 0xf2 or 0xf3.
There are two instructions which have the following base opcodes:
crc32 -- f2 0f 38 f0 (Here, 0xf2 is a mandatory prefix)
movbe -- 0f 38 f0
So, the opcodes of a 'movbe' instruction which has to repeat as long as the counter register is non-zero should be:
repnz movbe == f2 0f 38 f0
When I start disassembling an instruction, if I see the byte 0xf2, how do I know that it's a mandatory prefix for the crc32 instruction but not a repeat prefix for the movbe instruction, or vice-versa? Which instruction do I match the opcode pattern "f2 0f 38 f0" to?
What am I missing?
[1] http://www.intel.com/design/intarch/manuals/243191.HTM
Thanks and Regards,
Hrishikesh Murali
You can use the repeat prefixes only with string instructions (see the manual). "f2 0f 38 f0" is always CRC32 instruction.