9

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 ?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Simon
  • 2,067
  • 2
  • 17
  • 30
  • 1
    The REX prefix can also be used for [efficient alignment](https://stackoverflow.com/q/48046814/995714) even instructions that don't need one – phuclv Jul 14 '18 at 13:45

2 Answers2

12

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.

phuclv
  • 37,963
  • 15
  • 156
  • 475
adelphus
  • 10,116
  • 5
  • 36
  • 46
  • See Intel's SDM for full details (https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html#inpage-nav-2) and other docs in https://stackoverflow.com/tags/x86/info. Also https://wiki.osdev.org/X86-64_Instruction_Encoding#REX_prefix – Peter Cordes Apr 06 '22 at 04:38
7

It's not useless, but not overwhelmingly useful either.

A REX prefix changes ah, ch, dh and bh into spl, bpl, sil and dil (respectively). So while you cannot use the first set, you can use the second set.

harold
  • 61,398
  • 6
  • 86
  • 164