Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the 40h REX opcode in ASM x64?

I've been trying to understand the purpose of the 0x40 REX opcode for ASM x64 instructions. Like for instance, in this function prologue from Kernel32.dll:

enter image description here

As you see they use push rbx as:

40 53      push        rbx 

But using just the 53h opcode (without the prefix) also produces the same result:

enter image description here

According to this site, the layout for the REX prefix is as follows:

enter image description here

So 40h opcode seems to be not doing anything. Can someone explain its purpose?

like image 306
c00000fd Avatar asked Oct 17 '22 18:10

c00000fd


1 Answers

the 04xh bytes (i.e. 040h, 041h... 04fh) are indeed REX bytes. Each bit in the lower nibble has a meaning, as you listed in your question. The value 040h means that REX.W, REX.R, REX.X and REX.B are all 0. That means that adding this byte doesn't do anything to this instruction, because you're not overriding any default REX bits, and it's not an 8-bit instruction with AH/BH/CH/DH as an operand.

Moreover, the X, R and B bits all correspond to some operands. If your instruction doesn't consume these operands, then the corresponding REX bit is ignored.

like image 176
Nathan Fellman Avatar answered Oct 21 '22 07:10

Nathan Fellman