当前位置: 首页>>代码示例>>C#>>正文


C# Instruction.getAddress方法代码示例

本文整理汇总了C#中Instruction.getAddress方法的典型用法代码示例。如果您正苦于以下问题:C# Instruction.getAddress方法的具体用法?C# Instruction.getAddress怎么用?C# Instruction.getAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Instruction的用法示例。


在下文中一共展示了Instruction.getAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: decompile

        /// <summary>
        /// Function to decompile the lines read from a hex file.
        /// </summary>
        /// <returns>List with the flash memory abstraction.</returns>
        public List<picWord> decompile()
        {
            int Bytes, BaseAddress, CheckSum, i, bin;
            DataTypes DataType;
            List<int> DataBytes = new List<int>();
            List<picWord> sourceISA = new List<picWord>();
            foreach (String line in HexCode)
            {
                Bytes = Convert.ToInt32(line.Substring(1, BYTEBLOCK), 16);
                BaseAddress = Convert.ToInt32(line.Substring(BYTEBLOCK + 1, 2 * BYTEBLOCK), 16) >> 1;
                DataType = (DataTypes)Convert.ToInt32(line.Substring(3 * BYTEBLOCK + 1, BYTEBLOCK), 16);
                if (BaseAddress == 0x2007)
                {
                    // This is a configuration word... and its extremely poorly documented...
                    bin = Convert.ToInt32(line.Substring(5 * BYTEBLOCK + 1, BYTEBLOCK) +
                                                        line.Substring(4 * BYTEBLOCK + 1, BYTEBLOCK), 16);
                    sourceISA.Add(new picWord(bin, BaseAddress));
                    continue;
                }
                else if (DataType == DataTypes.ExtendedAddress)
                {
                    // This is data which was placed in the the PIC's flash memory. To avoid using the limited RAM.
                    for (i = 0; i < (Bytes * BYTEBLOCK) && (DataType == DataTypes.Program); i += 2 * BYTEBLOCK)
                    {
                        // Due to the little endian design of the instruction format, bytes need to be reverse in order to be usable.
                        bin = Convert.ToInt32(line.Substring(i + 5 * BYTEBLOCK + 1, BYTEBLOCK) +
                                                        line.Substring(i + 4 * BYTEBLOCK + 1, BYTEBLOCK), 16);
                        sourceISA.Add(new picWord(bin, BaseAddress));
                    }
                }
                else
                {
                    // This is an insrucion block.
                    for (i = 0; i < (Bytes * BYTEBLOCK) && (DataType == DataTypes.Program); i += 2 * BYTEBLOCK)
                    {
                        Queue<asmLabel> Labels = new Queue<asmLabel>();
                        Instruction I;
                        asmLabel L;
                        String[] args;
                        // Due to the little endian design of the instruction format, bytes need to be reverse in order to be usable.
                        bin = Convert.ToInt32(line.Substring(i + 5 * BYTEBLOCK + 1, BYTEBLOCK) +
                                                        line.Substring(i + 4 * BYTEBLOCK + 1, BYTEBLOCK), 16);
                        DataBytes.Add(bin);
                        try
                        {
                            // Start the BT by modifying the CPU Registers.
                            L = new asmLabel("", BaseAddress);
                            I = new Instruction(bin, BaseAddress + i / (2 * BYTEBLOCK), ref rf, ref ptrTOS);
                            args = I.getargs();
                            int addr = I.getAddress();
                            switch (I.getmnemonic())
                            {
                                // Managing labels while decompiling.
                                case "CALL":
                                    args = I.getargs();
                                    addr = bin & 0x07FF;
                                    L.label = args[0];
                                    L.address = addr;
                                    if (addr < I.getAddress())
                                        sourceISA.Find(x => x.getAddress() == addr).setLabel(ref L);
                                    else
                                        Labels.Enqueue(new asmLabel(args[0], addr));
                                    break;
                                case "GOTO":
                                    args = I.getargs();
                                    addr = bin & 0x07FF;
                                    L.label = args[0];
                                    L.address = addr;
                                    if (addr < I.getAddress())
                                        sourceISA.Find(x => x.getAddress() == addr).setLabel(ref L);
                                    else
                                        Labels.Enqueue(new asmLabel(args[0], addr));
                                    break;
                                default:
                                    break;
                            }
                            if ((Labels.Count > 0) && (I.getAddress() == Labels.Peek().address))
                            {
                                L = Labels.Dequeue();
                                I.setLabel(ref L);
                            }
                            sourceISA.Add(I);

                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Something horrible happenned:");
                            Console.WriteLine(e.Message);
                            Console.WriteLine("Instruction skipped.");
                            //throw e;
                        }

                    }
                }
                CheckSum = Convert.ToInt32(line.Substring(line.Length - BYTEBLOCK, BYTEBLOCK), 16);
            }
//.........这里部分代码省略.........
开发者ID:eliasv,项目名称:PicSim,代码行数:101,代码来源:PIC.cs


注:本文中的Instruction.getAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。