X86 Encoder Decoder
 All Files Groups Pages
High Level API for Encoding Instructions

This is a higher level API for encoding instructions.

A full example is present in examples/xed-ex5-enc.c

In the following example we create one instructions template that can be passed to the encoder.

xed_encoder_instruction_t x;
xed_encoder_request_t enc_req;
xed_state_t dstate;
dstate.mmode=XED_MACHINE_MODE_LEGACY_32;
dstate.stack_addr_width=XED_ADDRESS_WIDTH_32b;
xed_inst2(&x, dstate, XED_ICLASS_ADD, 0,
xreg(XED_REG_EAX),
xmem_bd(XED_REG_EDX, xdisp(0x11223344, 32), 32));
xed_encoder_request_zero_set_mode(&enc_req, &dstate);
convert_ok = xed_convert_to_encoder_request(&enc_req, &x);
if (!convert_ok) {
fprintf(stderr,"conversion to encode request failed\n");
continue;
}
xed_error = xed_encode(&enc_req, itext, ilen, &olen);

The high-level encoder interface allows passing the effective operand width for the xed_inst*() function as 0 (zero) when the effective operand width is the default.

The default width in 16b mode is 16b. The default width in 32b or 64b modes is 32b. So if you do a 16b operation in 32b/64b mode, you must set the effective operand width. If you do a 64b operation in 64b mode, you must set it (the default is 32). Or if you do a more rare 32b operation in 16b mode you must also set it.

When all the operands are "suppressed" operands, then the effective operand width must be supplied for nondefault operation widths.