Search code examples
assemblyx86-64cpu-registersinstruction-set

What's the point of instructions with only the REX prefix in 64bit mode?


For example one of the MOV has 2 versions, one with REX, one without (from Intel's doc) :

88 /r MOV r/m8, r8
REX + 88 /r MOV r/m8***, r8***

***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.

From what I understand, the 2 instructions are identical except the second one uses an additional byte and provides less options ... So basically it is useless.

What am I missing ?


Solution

  • It's to do with the encoding of the registers in the instruction. The bits available in the r/m part select from a set of registers - those registers change, depending upon the REX prefix:

    Available 8-bit registers without REX prefix:

    AL, CL, DL, BL, AH, CH, DH, BH

    Available 8-bit registers with REX prefix set:

    AL, CL, DL, BL, SPL, BPL, SIL, DIL, R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B

    This is why Intel docs draw attention to the fact that you cannot select certain registers with the REX prefix set.