Example #1
0
            /// <summary>
            /// Constructs the representation of this instruction variant using the specified operands.
            /// </summary>
            /// <param name="context">The <see cref="Context"/> used.</param>
            /// <param name="operands">The <see cref="Operand"/> objects to encode.</param>
            /// <param name="lockPrefix">Whether to use a lock prefix.</param>
            /// <returns>The encoded instruction.</returns>
            public EncodedInstruction Construct(Context context, IEnumerable <IConstructableOperand> operands, bool lockPrefix)
            {
                #region Contract
                Contract.Requires <ArgumentNullException>(context != null);
                Contract.Requires <ArgumentNullException>(operands != null);
                Contract.Ensures(Contract.Result <EncodedInstruction>() != null);
                #endregion

                EncodedInstruction instr = new EncodedInstruction();

                // Set the lock prefix.
                instr.SetLock(lockPrefix);

                // Set the opcode.
                instr.Opcode = opcode;

                // Set the fixed REG value, if any.
                instr.FixedReg = fixedReg;

                int i = 0;
                foreach (var operand in operands)
                {
                    if (operand == null)
                    {
                        // No operand. Nothing to do.
                        continue;
                    }
                    if (i >= descriptors.Length)
                    {
                        // No descriptors left. Nothing to be done.
                        break;
                    }

                    operand.Adjust(descriptors[i]);
                    operand.Construct(context, instr);
                    i++;
                }

                // When the operand size has been explicitly set, set it on the encoded instruction.
                if (operandSize != DataSize.None)
                {
                    instr.SetOperandSize(context.Representation.Architecture.OperandSize, operandSize);
                }

                // We are done.
                return(instr);
            }
Example #2
0
        /// <summary>
        /// Constructs the representation of this instruction variant using the specified operands.
        /// </summary>
        /// <param name="context">The <see cref="Context"/> used.</param>
        /// <param name="operands">The <see cref="Operand"/> objects to encode.</param>
        /// <param name="lockPrefix">Whether to use a lock prefix.</param>
        /// <returns>The encoded instruction.</returns>
        public EncodedInstruction Construct(Context context, IEnumerable <Operand> operands, bool lockPrefix)
        {
            var instr = new EncodedInstruction(opcodeBytes, FixedReg, lockPrefix);

            int i = 0;

            foreach (var operand in operands)
            {
                if (operand == null)
                {
                    // No operand. Nothing to do.
                    continue;
                }
                if (i >= Descriptors.Count)
                {
                    // No descriptors left. Nothing to be done.
                    break;
                }

                operand.Adjust(Descriptors[i]);
                operand.Construct(context, instr);
                i++;
            }

            // When the operand size has been explicitly set, set it on the encoded instruction.
            if (OperandSize != DataSize.None)
            {
                instr.SetOperandSize(context.AddressingMode, OperandSize);
            }
            if (NoRexPrefix)
            {
                // SetOperandSize() will cause the instruction to encode a REX prefix, which is not required in
                // this particular case. So reset it back to null to encode no REX prefix.
                instr.Use64BitOperands = null;
            }

            // We are done.
            return(instr);
        }