X86 Encoder Decoder
 All Files Groups Pages
Encoding Instructions
When you call xed_encode() to encode instruction you must pass:
   <ul>
   <li> an encode structure that includes a machine state ( #xed_state_t )
   <li> a pointer to the instruction text
   <li> a length of the text array
   </ul>
The class #xed_encoder_request_t includes a #xed_operand_values_t and
that is where most of the information about the operands,
resources etc. are stored.

To add a REP or REPNE prefix to a an encoder request, set it in
the encoder request directly by calling
#xed_encoder_request_set_rep() or
#xed_encoder_request_set_repne().

To get nondefault width operands, during encoding, you have to
call #xed_encoder_request_set_effective_operand_width() .


To set nondefault addressing widths, you must call
#xed_encoder_request_set_effective_address_size().



To encode instructions you must set the following 

in the #xed_encoder_request_t.

  1. the machine mode (machine width, and stack addressing width)
  2. the effective operand width
  3. the iclass
  4. for some instructions you need to specify prefixes (like REP, REPNE or LOCK).
  5. the operands:
    1. operand kind (XED_OPERAND_{AGEN,MEM0,MEM1,IMM0,IMM1,RELBR,PTR,REG0...REG15}

    2. operand order
      xed_encoder_request_set_operand_order(&req,operand_index, XED_OPERAND_*); where the operand_index is a sequential index starting at zero.

    3. operand details
      1. FOR MEMOPS: base,segment,index,scale,displacement for memops,
      2. FOR REGISTERS: register name
      3. FOR IMMEDIATES: immediate values

See An example of using the encoder for an example of using the encoder.