pub struct Rex {
pub opcodes: Opcodes,
pub w: bool,
pub r: bool,
pub digit: Option<u8>,
pub imm: Imm,
}
Expand description
The traditional x64 encoding.
We use the “REX” name here in a slightly unorthodox way: “REX” is the name for the optional byte extending the number of available registers, e.g., but we use it here to distinguish this from other encoding formats (e.g., VEX, EVEX). The “REX” byte is still optional in this encoding and only emitted when necessary.
Fields§
§opcodes: Opcodes
The opcodes for this instruction.
Multi-byte opcodes are handled by passing an array of opcodes (including
prefixes like 0x66
and escape bytes like 0x0f
) to the constructor.
E.g., 66 0F 54
(ANDPD
) is expressed as follows:
let enc = rex([0x66, 0x0f, 0x54]);
w: bool
Indicates setting the REX.W bit.
From the reference manual: “Indicates the use of a REX prefix that affects operand size or instruction semantics. The ordering of the REX prefix and other optional/mandatory instruction prefixes are discussed in chapter 2. Note that REX prefixes that promote legacy instructions to 64-bit behavior are not listed explicitly in the opcode column.”
r: bool
From the reference manual: “indicates that the ModR/M byte of the instruction contains a register operand and an r/m operand.”
digit: Option<u8>
From the reference manual: “a digit between 0 and 7 indicates that the ModR/M byte of the instruction uses only the r/m (register or memory) operand. The reg field contains the digit that provides an extension to the instruction’s opcode.”
imm: Imm
The number of bits used as an immediate operand to the instruction.
From the reference manual: “a 1-byte (ib), 2-byte (iw), 4-byte (id) or 8-byte (io) immediate operand to the instruction that follows the opcode, ModR/M bytes or scale-indexing bytes. The opcode determines if the operand is a signed value. All words, doublewords, and quadwords are given with the low-order byte first.”
Implementations§
Source§impl Rex
impl Rex
Sourcepub fn r(self) -> Self
pub fn r(self) -> Self
Set the ModR/M byte to contain a register operand and an r/m operand;
equivalent to /r
in the reference manual.
Sourcepub fn digit(self, digit: u8) -> Self
pub fn digit(self, digit: u8) -> Self
Set the digit extending the opcode; equivalent to /<digit>
in the
reference manual.
§Panics
Panics if digit
is too large.
Sourcepub fn ib(self) -> Self
pub fn ib(self) -> Self
Append a byte-sized immediate operand (8-bit); equivalent to ib
in the
reference manual.
§Panics
Panics if an immediate operand is already set.
Sourcepub fn iw(self) -> Self
pub fn iw(self) -> Self
Append a word-sized immediate operand (16-bit); equivalent to iw
in
the reference manual.
§Panics
Panics if an immediate operand is already set.