Example #1
0
        public static string Disassembly(int[] code)
        {
            string      program = "";
            Instruction instr;
            int         i = 0;

            while (i < code.Length)
            {
                instr    = InstructionSet.Get(code[i]);
                program += instr.Name + " ";
                if (instr.NumOperands > 0)
                {
                    if (instr.Name == "cstr")
                    {
                        string cstr = string.Join("", code.Skip(i + 1).TakeWhile((ch, index) => ch != 0).Select(ch => (char)ch).ToArray());
                        program += "\"" + cstr + "\"";
                        i       += cstr.Length + 1;
                    }
                    else
                    {
                        program += string.Join(", ", code.Skip(i + 1).Take(instr.NumOperands).ToArray());
                        i       += instr.NumOperands;
                    }
                }
                i++;
                program += "\n";
            }

            return(program);
        }
Example #2
0
 public void Continue()
 {
     while (GetFlag(F.Halt) == false)
     {
         IP = XP;
         try
         {
             InstructionSet.Get(Next()).Execute(this);
         }
         catch (ArgumentOutOfRangeException e)
         {
             Console.WriteLine(e.Message);
         }
     }
     SetFlag(F.Halt, false);
 }