pub struct Rex {
pub opcodes: Opcodes,
pub w: bool,
pub modrm: Option<ModRmKind>,
pub imm: Imm,
pub opcode_mod: Option<OpcodeMod>,
}
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.”
modrm: Option<ModRmKind>
Indicates modifications to the ModR/M byte.
imm: Imm
The number of bits used as an immediate operand to the instruction.
opcode_mod: Option<OpcodeMod>
Used for +rb
, +rw
, +rd
, and +ro
instructions, which encode reg
bits in the opcode byte; if Some
, this contains the expected bit width
of reg
.
From the reference manual: “[…] the lower 3 bits of the opcode byte is used to encode the register operand without a modR/M byte. The instruction lists the corresponding hexadecimal value of the opcode byte with low 3 bits as 000b. In non-64-bit mode, a register code, from 0 through 7, is added to the hexadecimal value of the opcode byte. In 64-bit mode, indicates the four bit field of REX.b and opcode[2:0] field encodes the register operand of the instruction. “+ro” is applicable only in 64-bit mode.”
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, extension: u8) -> Self
pub fn digit(self, extension: u8) -> Self
Set the digit extending the opcode; equivalent to /<digit>
in the
reference manual.
§Panics
Panics if extension
is too large.
Sourcepub fn unwrap_digit(&self) -> Option<u8>
pub fn unwrap_digit(&self) -> Option<u8>
Retrieve the digit extending the opcode, if available.
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.
Sourcepub fn id(self) -> Self
pub fn id(self) -> Self
Append a doubleword-sized immediate operand (32-bit); equivalent to id
in the reference manual.
§Panics
Panics if an immediate operand is already set.
Sourcepub fn io(self) -> Self
pub fn io(self) -> Self
Append a quadword-sized immediate operand (64-bit); equivalent to io
in the reference manual.
§Panics
Panics if an immediate operand is already set.
Sourcepub fn rb(self) -> Self
pub fn rb(self) -> Self
Modify the opcode byte with bits from an 8-bit reg
; equivalent to
+rb
in the reference manual.
Sourcepub fn rw(self) -> Self
pub fn rw(self) -> Self
Modify the opcode byte with bits from a 16-bit reg
; equivalent to
+rw
in the reference manual.