Macro zydis::mem

source ·
macro_rules! mem {
    ($size:tt ptr [ $($base_index_scale_disp:tt)* ]) => { ... };
}
Expand description

Macro for creating memory operands.

The general form is: somesize ptr [base + index * scale + disp]

All but one of base, index, scale and disp can be omitted, but the order must be kept. For example you can’t start with the disp and then add an index expression after that.

All identifiers are parsed as register names (Register::$ident). If you want to insert variables or expressions into the macro invocation, you must wrap them in parenthesis.

§Example

// Literal operands. All `ident`s are assumed to be register names.
mem!(qword ptr [0x1234]);
mem!(dword ptr [RAX + 0x1234]);
mem!(dword ptr [RSI * 8]);
mem!(dword ptr [RDX + RSI * 8]);
mem!(dword ptr [RDX + RSI * 8 + 0x1234]);

// Operands with dynamic expressions must use parenthesis!
let my_dyn_disp = 0x1234 + 837434;
let my_dyn_reg = Register::RBX;
mem!(qword ptr [(my_dyn_disp)]);
mem!(qword ptr [(my_dyn_reg)]);
mem!(qword ptr [(my_dyn_reg) * (2 + 2)]);
mem!(qword ptr [(my_dyn_reg) * 4 + (my_dyn_disp)]);
mem!(qword ptr [RAX * (4 * 2) + 0x1234]);