Esempio n. 1
0
        public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options)
        {
            if ((options & MachineInstructionWriterOptions.ExplicitOperandSize) != 0)
            {
                string s;
                if (Width == PrimitiveType.Byte)
                {
                    s = "byte ptr ";
                }
                else if (Width == PrimitiveType.Word16)
                {
                    s = "word ptr ";
                }
                else if (Width.Size == 4)
                {
                    s = "dword ptr ";
                }
                else if (Width == PrimitiveType.Word64)
                {
                    s = "qword ptr ";
                }
                else if (Width == PrimitiveType.Real32)
                {
                    s = "float ptr ";
                }
                else if (Width == PrimitiveType.Real64)
                {
                    s = "double ptr ";
                }
                else if (Width == PrimitiveType.Real80 || Width == PrimitiveType.Bcd80)
                {
                    s = "tword ptr ";
                }
                else if (Width == PrimitiveType.Word128)
                {
                    s = "xmmword ptr ";
                }
                else if (Width == PrimitiveType.Word256)
                {
                    s = "ymmword ptr ";
                }
                else
                {
                    s = "";
                }
                writer.WriteString(s);
            }

            if (SegOverride != RegisterStorage.None)
            {
                writer.WriteString(SegOverride.ToString());
                writer.WriteString(":");
            }
            writer.WriteString("[");
            if (Base != RegisterStorage.None)
            {
                writer.WriteString(Base.ToString());
            }
            else
            {
                var s = FormatUnsignedValue(Offset !);
                writer.WriteAddress(s, Address.FromConstant(Offset !));
            }

            if (Index != RegisterStorage.None)
            {
                writer.WriteString("+");
                writer.WriteString(Index.ToString());
                if (Scale > 1)
                {
                    writer.WriteString("*");
                    writer.WriteUInt32(Scale);
                }
            }
            if (Base != RegisterStorage.None && Offset != null && Offset.IsValid)
            {
                if (Offset.DataType == PrimitiveType.Byte || Offset.DataType == PrimitiveType.SByte)
                {
                    writer.WriteString(FormatSignedValue(Offset));
                }
                else
                {
                    var off = Offset.ToInt32();
                    if (off == Int32.MinValue)
                    {
                        writer.WriteString("-80000000");
                    }
                    else
                    {
                        var absOff = Math.Abs(off);
                        if (Offset.DataType.Size > 2 && off < 0 && absOff < 0x10000)
                        {
                            // Special case for negative 32-bit offsets whose
                            // absolute value < 0x10000 (GitHub issue #252)
                            writer.WriteString("-");
                            writer.WriteFormat("{0:X8}", absOff);
                        }
                        else
                        {
                            writer.WriteString("+");
                            writer.WriteString(FormatUnsignedValue(Offset));
                        }
                    }
                }
            }
            writer.WriteString("]");
        }