1

On this chart it shows that both registers have the 0b010 for the register value:

enter image description here

What is the X value here? In dissassembling the following two instructions:

add $1, %dl
add $1, %r10b

I get:

>>> x/3bt $pc
0x401000 <_start>:                  10000000    11000010    00000001
>>> x/4bt $pc+3
0x401003 <_start+3>:    01000001    10000000    11000010    00000001

So, I'm guessing the X is the LSB in the prefix byte since the 0100 is static, correct? What does the X mean and what does that mean whenever one of the r8-r15 registers is used an extra byte needs to be added/prefixed in order to say that "This is register r10 not rdx" ?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
carl.hiass
  • 1,526
  • 1
  • 6
  • 26

1 Answers1

4

X is a placeholder in that table you linked at the top of the page. It applies any time there's a register number in machine code. The leading bit comes from one of the fields in the REX prefix, depending on which which field this is.

That's why the leading bit is separated from the other 3 in the 0.010 bit pattern; with no REX prefix it's implicitly 0.

In your case, it's the .B bit because it's modifying the r/m field of ModRM in add $imm8, r/m8. (And because we can can see it's the low bit of the REX prefix).

The REX prefix (another section on the same page you linked) is how x86-64 added 8 new registers, and a choice of 32 or 64-bit operand-size, via a prefix without modifying the rest of the instruction encoding. 16 and 32-bit x86 machine code of course uses 3-bit fields for register numbers.

The REX prefix can provide a 4th reg-num bit for instructions like add r8, [rcx + r9*8] which includes 3 register numbers (MODRM.reg, MODRM.rm or SIB.base, and SIB.index). And has the .W bit set for 64-bit operand size.

The choice of X as a placeholder is slightly confusing because one of the REX fields is named X (the SIB.index). But that's not what they're referring to.


Also note that r10l and r10b are alternate names for the same register. AMD originally used r8-15b ("byte") when defining AMD64. Intel apparently invented the r8-15l ("low") names later (for similarity with AL/CL/DL/BL/SPL/...), but the b names are more popular and widespread. Why does Apple use R8l for the byte registers instead of R8b?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847