Struct Rex

Source
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

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, digit: u8) -> Self

Set the digit extending the opcode; equivalent to /<digit> in the reference manual.

§Panics

Panics if digit is too large.

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.

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.