Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 276
Simon Avatar asked Dec 27 '14 12:12

Simon


People also ask

What is REX prefix in assembly?

REX prefixes are instruction-prefix bytes used in 64-bit mode. They do the following: • • Specify 64-bit operand size.

What is the purpose of Rex in microprocessor?

The REX prefix is also used for mov instructions with 64-bit immediate operands; the default operand size, even in 64-bit mode, is 32-bits. All of these have to do with extending existing instructions to support 64-bit operation.

What does the prefix Rex mean?

The Latin title rex has the meaning of "king, ruler" (monarch). It is derived from Proto-Indo-European *h₃rḗǵs. Its cognates include Sanskrit rājan, Gothic reiks, and Old Irish rí, etc. Its Greek equivalent is archon (ἄρχων), "leader, ruler, chieftain".

What are the values of the SIB ModR m and displacement bytes for the x86 instruction?

Opcode with prefixes (1-4 bytes, required) ModR/M (1 byte, if required) SIB (1 byte, if required) Displacement (1, 2, 4 or 8 bytes, if required)


Video Answer


2 Answers

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.

like image 84
harold Avatar answered Oct 22 '22 17:10

harold


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.

like image 20
adelphus Avatar answered Oct 22 '22 18:10

adelphus