Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to keep a word sized immediate in a 32bit register instruction

Assume the following x86-32 instruction:

add ebx,1

There are (at least) two ways to assemble this opcode:

81 c3 01 00 00 00

or

83 c3 01

The first keeps 1 as a 4 bytes dword the second keeps 1 as a byte

Is there an instruction that keeps 1 as 2 bytes? If no why?

like image 829
user1677989 Avatar asked Jun 29 '13 11:06

user1677989


1 Answers

You have stumbled upon a quirk of the x86 instruction set. Intel included a group of instructions under the stem 83, whose first operand is of type Ev, and whose second operand is an immediate byte that is interpreted as being the same size as the Ev operand. So for 83 c3 01, the 01 is interpreted as a 32-bit value; for 66 83 c3 01, the 01 is interpreted as a 16-bit value (and the destination is the 16-bit ax register). The push mnemonic coded under the stem 6A behaves in the same way with respect to the size of its single operand.

The broader answer to your question is no, there is no encoding where a 16-bit constant is interpreted as a 32-bit one.

Source: I wrote a disassembler.

like image 128
Syzygy Avatar answered Oct 29 '22 19:10

Syzygy