Пример #1
0
    protected bool GetOperandAddr(int count)
    {
        int eip = FReg.EIP;

        for (int i = 0; i < count; i++)
        {
            Addressing addressing = (Addressing)FMem.ReadByte(eip);
            if (!IsSupportAddressing(addressing))
            {
                Error = "unsupport register" + addressing.ToString();
                return(false);
            }
            eip++;
            if (addressing == Addressing.imm)
            {
                if (FCpuWidth == 2)
                {
                    ushort imm = FMem.ReadWord(eip);
                    eip    += 2;
                    Addr[i] = FReg.GetRegisterAddr(addressing);
                    FReg.WriteWord(Addr[i], imm);
                }
                else if (FCpuWidth == 4)
                {
                    Int32 imm = FMem.ReadInt(eip);
                    eip    += 4;
                    Addr[i] = FReg.GetRegisterAddr(addressing);
                    FReg.WriteInt(Addr[i], imm);
                }
                else
                {
                    ushort imm = FMem.ReadWord(eip);
                    eip    += 2;
                    Addr[i] = FReg.GetRegisterAddr(addressing);
                    FReg.WriteWord(Addr[i], imm);
                }
            }
            else if (addressing == Addressing.mem)
            {
                /*
                 * if 8bit
                 * base register is only bp
                 * index register can si or di sp
                 * scale can be 1, 2, 4, 8
                 * imm is 16bit
                 * if 16bit
                 * base register can bp or bx
                 * index register can ax, cx, dx, si, di, sp
                 * scale can be 1, 2, 4, 8
                 * imm is 16bit
                 * if 32bit
                 * base register can ebx, bp or bx
                 * index register can eax, ecx, edx, esi, edi, esp, ax, cx, dx, si, di, sp
                 * scale can be 1, 2, 4, 8
                 * imm is 32bit
                 */
                int addr = 0;
                //seg reg
                addressing = (Addressing)FMem.ReadByte(eip);
                eip++;
                addr = (ushort)FReg.ReadWord(addressing) << 4;
                //base reg
                addressing = (Addressing)FMem.ReadByte(eip);
                eip++;
                if (addressing != Addressing.none)
                {
                    addr = addr + FReg.ReadWord(Addressing.bp);
                }
                //index reg
                addressing = (Addressing)FMem.ReadByte(eip);
                eip++;
                //scale
                int scale = FMem.ReadByte(eip);
                eip++;
                if (addressing != Addressing.none)
                {
                    addr = addr + FReg.ReadWord(addressing) * scale;
                }

                //imm
                if (FCpuWidth == 2)
                {
                    addr = addr + FMem.ReadWord(eip);
                    eip  = eip + 2;
                }
                else if (FCpuWidth == 4)
                {
                    addr = addr + FMem.ReadInt(eip);
                    eip += 4;
                }
                else
                {
                    addr = addr + FMem.ReadWord(eip);
                    eip  = eip + 2;
                }

                Addr[i] = addr;
            }
            else
            {
                Addr[i] = FReg.GetRegisterAddr(addressing);
            }
            FReg.EIP = eip;
        }
        return(true);
    }
Пример #2
0
 public override string ToString()
 {
     return(SR.Format(SR.MessageVersionToStringFormat, Envelope.ToString(), Addressing.ToString()));
 }
Пример #3
0
    public void EmitRegister(int index)
    {
        Addressing addressing = opcode.Register[index];

        switch (addressing)
        {
        case Addressing.eax:
        case Addressing.ebx:
        case Addressing.ecx:
        case Addressing.edx:
        case Addressing.ebp:
        case Addressing.esp:
        case Addressing.esi:
        case Addressing.edi:
        case Addressing.ax:
        case Addressing.bx:
        case Addressing.cx:
        case Addressing.dx:
        case Addressing.ah:
        case Addressing.bh:
        case Addressing.ch:
        case Addressing.dh:
        case Addressing.al:
        case Addressing.bl:
        case Addressing.cl:
        case Addressing.dl:
        case Addressing.bp:
        case Addressing.sp:
        case Addressing.si:
        case Addressing.di:
        case Addressing.cs:
        case Addressing.ds:
        case Addressing.es:
        case Addressing.fs:
        case Addressing.ss:
            WriteByte((byte)addressing);
            Console.Write("%" + addressing.ToString());
            break;

        case Addressing.imm:
            WriteByte((byte)Addressing.imm);
            if (CpuWidth == 2)
            {
                WriteWord((short)opcode.Imm);
            }
            else if (CpuWidth == 4)
            {
                WriteInt(opcode.Imm);
            }
            else
            {
                WriteWord((short)opcode.Imm);
            }
            Console.Write("$" + opcode.Imm);
            break;

        case Addressing.mem:
            WriteByte((byte)Addressing.mem);
            WriteByte((byte)opcode.SegReg);
            WriteByte((byte)opcode.BaseReg);
            WriteByte((byte)opcode.IndexReg);
            WriteByte(opcode.scale);
            string segreg = "";
            if (opcode.SegReg != Addressing.ds)
            {
                segreg = "%" + opcode.SegReg.ToString() + ":";
            }
            string basereg = "";
            if (opcode.BaseReg != Addressing.none)
            {
                basereg = "%" + opcode.BaseReg.ToString();
            }
            string indexreg = "";
            if (opcode.IndexReg != Addressing.none)
            {
                indexreg = ",%" + opcode.IndexReg.ToString();
            }
            string scalestring = "";
            if (opcode.scale > 0)
            {
                scalestring = "," + opcode.scale.ToString();
            }

            if (CpuWidth == 2)
            {
                WriteWord((short)opcode.MemImm);
            }
            else if (CpuWidth == 4)
            {
                WriteInt(opcode.MemImm);
            }
            else
            {
                WriteWord((short)opcode.MemImm);
            }
            if (opcode.MemImm > 0)
            {
                Console.Write(segreg + opcode.MemImm.ToString() + "(" + basereg + indexreg + scalestring + ")");
            }
            else
            {
                Console.Write(segreg + "(" + basereg + indexreg + scalestring + ")");
            }
            break;

        case Addressing.backfill:
            BackFillAddrList.Add(new Tuple <int, string, int, int>(DataIndex, opcode.BackFillLabel, opcode.LineNo, opcode.RowNo));
            WriteInt(opcode.Imm);
            Console.Write(opcode.Imm);
            break;

        default:
            break;
        }
    }