예제 #1
0
        public static AssemblableCommand DisassembleNextCommand(ApplicationContext context, IMemorizable memory)
        {
            AssemblableCommand cmd;
            uint lenght = 0;

            try {
                lenght = (uint)GetCommandLength(context, memory.ExtractMemoryPointer(0, memory.Length));
            } catch {
                cmd = new AssemblableCommand(CommandTemplate.UNKNOWN);
                return(cmd);
            }

            cmd = Dissassemble(context, memory.ExtractMemoryPointer(0, (int)lenght));

            return(cmd);
        }
예제 #2
0
        public byte[] Assemble(string instruction)
        {
            var cmd = new AssemblableCommand(context, instruction);

            return(cmd.Assemble());
        }
예제 #3
0
        public static AssemblableCommand Dissassemble(ApplicationContext ctx, IMemorizable pointer)
        {
            AssemblableCommand command;
            int inizioPar = -1;

            List <CommandTemplate> allcmds = ctx.CommandTemplList.Where(el => {
                var ret = true;

                for (var i = 0;; i += 2)
                {
                    if (pointer.Length < i || el.OpCode.Length <= i || el.OpCode.Substring(i, 2).Contains('$') || !ret)
                    {
                        inizioPar = i;
                        break;
                    }

                    ret = MySupport.ByteArrayToString(pointer.GetValues(i / 2, 1)) == el.OpCode.Substring(i, 2);
                }
                return(ret);
            }).ToList();

            if (allcmds.Count > 1)
            {
                throw new Exception("Multple commands with a single opCode");
            }


            CommandTemplate template = allcmds[0];

            if (!template.OpCode.Contains("$"))
            {
                return(new AssemblableCommand(template));
            }

            inizioPar = template.OpCode.IndexOf("$" /*, inizioPar*/); // TOLTO A CASO PERCHE NON ANDAVA

            int spar = -1;

            var parms = new string[2];

            if (inizioPar != template.OpCode.Length / 2)
            {
                int np = sbyte.Parse(template.OpCode[inizioPar + 3].ToString()) - 1;

                sbyte p2size =
                    sbyte.Parse(template.ParTypes[np].ToString().Substring(template.ParTypes[np].ToString().Length - 2));
                p2size /= 8;

                parms[np] = template.OpCode.Substring(inizioPar + 5, 2) != "le"
                    ? MySupport.ByteArrayToString(pointer.GetValues(inizioPar / 2, p2size))
                    : MySupport.ByteArrayToString(pointer.GetValues(inizioPar / 2, p2size).Reverse().ToArray());


                inizioPar = template.OpCode.IndexOf("$", template.OpCode.IndexOf("$", inizioPar + 1) + 1);
                spar      = inizioPar / 2 + p2size;
            }

            // Parameters are always attached.

            if (inizioPar != template.OpCode.Length / 2 && inizioPar != -1)
            {
                int np = sbyte.Parse(template.OpCode[inizioPar + 3].ToString()) - 1;

                sbyte p2size =
                    sbyte.Parse(template.ParTypes[np].ToString().Substring(template.ParTypes[np].ToString().Length - 2));
                p2size /= 8;

                parms[np] = template.OpCode.Substring(inizioPar + 5, 2) != "le"
                    ? MySupport.ByteArrayToString(pointer.GetValues(spar / 2, p2size))
                    : MySupport.ByteArrayToString(pointer.GetValues(spar / 2, p2size).Reverse().ToArray());
            }

            command = new AssemblableCommand(template, ctx, template.ParTypes, parms);

            return(command);
        }