1

For these two instructions (https://www.felixcloutier.com/x86/adc):

12 /r ADC r8, r/m8 - Add with carry r/m8 to byte register.
REX + 12 /r ADC r8*, r/m8* - Add with carry r/m641 to byte register.

*In 64-bit mode, r/m8 can not be encoded to access the following byte registers if a REX prefix is used: AH, BH, CH, DH.

Both of these can have the REX prefix if the register on the first instruction is 9-16... So how does the CPU differentiate between the two? Is the REX prefix on the first instruction missing the 1 in the 7th bit so it's just REX.B 0x01?


Footnote 1: editor's note: That's a typo in Intel's manual. Both are 8-bit operand-size, so both should describe an "r/m8" source, not "r/m64". 16/32/64-bit operand-size has a different opcode than 8-bit, and REX.W or a 66h prefix select the operand-size attribute.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Ryan Brown
  • 1,017
  • 1
  • 13
  • 34

1 Answers1

3

No, obviously not. The first one doesn't have a REX prefix, and the second one does. The first form by definition has no REX prefix, and therefore cannot have it (that would, again by definition, make it the second form instead). The reason they are both in the manual is so there can be asterisks next to the form with a REX prefix, and a note that it can't encode AH, BH, CH, or DH.

Is the REX prefix on the first instruction missing the 1 in the 7th bit so it's just REX.B 0x01?

That makes no sense.

So how does the CPU differentiate between the two?

Well, one has a REX prefix and the other does not.

harold
  • 61,398
  • 6
  • 86
  • 164
  • In case it's not obvious why it can't encode [A-D]H, having a REX prefix changes the meaning of some register numbers for 8-bit registers: SPL instead of AH, DIL instead of BH, etc. This is the use-case for a REX prefix with no bits set, just `40h`. – Peter Cordes Jul 27 '23 at 04:23