Пример #1
0
        /// <summary>
        /// Formats an instruction to a readable string.
        /// </summary>
        /// <param name="formatter">The formatter to use.</param>
        /// <param name="instruction">The isntruction to format.</param>
        /// <returns>The formatted operand.</returns>
        public static string FormatInstruction(this IX86Formatter formatter, X86Instruction instruction)
        {
            var mnemonicString = formatter.FormatMnemonic(instruction.Mnemonic);

            if (instruction.Operand2 == null)
            {
                return(instruction.Operand1 == null
                    ? mnemonicString
                    : mnemonicString + ' ' + formatter.FormatOperand(instruction.Operand1));
            }

            return(mnemonicString + ' ' + formatter.FormatOperand(instruction.Operand1) + ", " +
                   formatter.FormatOperand(instruction.Operand2));
        }
Пример #2
0
        /// <summary>
        /// Formats an instruction to a readable string.
        /// </summary>
        /// <param name="formatter">The formatter to use.</param>
        /// <param name="instruction">The isntruction to format.</param>
        /// <returns>The formatted operand.</returns>
        public static string FormatInstruction(this IX86Formatter formatter, X86Instruction instruction)
        {
            string prefixesString = string.Join(" ",
                                                from prefix in instruction.Prefixes
                                                let formatted = formatter.FormatPrefix(prefix)
                                                                where !string.IsNullOrEmpty(formatted)
                                                                select formatted);

            string mnemonicString = formatter.FormatMnemonic(instruction.Mnemonic);

            var operands = new[] { instruction.Operand1, instruction.Operand2, instruction.Operand3 }
            .TakeWhile(x => x != null).Select(formatter.FormatOperand);
            string operandsString = string.Join(", ", operands);

            return(string.Format("{0}{1}{2}",
                                 string.IsNullOrEmpty(prefixesString) ? string.Empty : prefixesString + ' ',
                                 mnemonicString,
                                 string.IsNullOrEmpty(operandsString) ? string.Empty : ' ' + operandsString));
        }