Struct Rex

Source
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

Source

pub fn w(self) -> Self

Set the REX.W bit.

Source

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.

Source

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.

Source

pub fn unwrap_digit(&self) -> Option<u8>

Retrieve the digit extending the opcode, if available.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn rb(self) -> Self

Modify the opcode byte with bits from an 8-bit reg; equivalent to +rb in the reference manual.

Source

pub fn rw(self) -> Self

Modify the opcode byte with bits from a 16-bit reg; equivalent to +rw in the reference manual.

Source

pub fn rd(self) -> Self

Modify the opcode byte with bits from a 32-bit reg; equivalent to +rd in the reference manual.

Source

pub fn ro(self) -> Self

Modify the opcode byte with bits from a 64-bit reg; equivalent to +ro in the reference manual.

Trait Implementations§

Source§

impl Display for Rex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Rex> for Encoding

Source§

fn from(rex: Rex) -> Encoding

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Rex

§

impl RefUnwindSafe for Rex

§

impl Send for Rex

§

impl Sync for Rex

§

impl Unpin for Rex

§

impl UnwindSafe for Rex

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.