Ejemplo n.º 1
0
 private void stopButton_Click(object sender, EventArgs e)
 {
     system.EndWorking();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Method that executes binary code.
 /// </summary>
 public void Execute()
 {
     try
     {
         cpu.Constants.GetRegister("pc").Val = entryPoint;
         LinkedList <Instruction> instructions = new LinkedList <Instruction>();
         LinkedList <byte>        binary       = new LinkedList <byte>();
         Thread.BeginCriticalRegion();
         executing = true;
         Thread.EndCriticalRegion();
         Variables vars = new Variables();
         vars.SetVariable("working", true);
         while (true)
         {
             int pc = cpu.Constants.GetRegister("pc").Val;
             cpu.CheckForInterupts(vars);
             if (separators.Contains(pc) && pc != entryPoint)
             {
                 Instruction         inst = cpu.Constants.MatchInstruction(binary.ToArray());
                 InstructionRegister ir   = new InstructionRegister(binary.ToArray());
                 inst.ReadAddressingModes(binary.ToArray());
                 int[] operands = inst.FetchOperands(ir, cpu, vars);
                 int[] result   = inst.Execute(ir, cpu, vars, operands);
                 inst.StoreResult(ir, cpu, vars, result);
                 binary.Clear();
                 pc = cpu.Constants.GetRegister("pc").Val;
             }
             if (pc - entryPoint >= binary.Count() || (bool)vars.GetVariable("working") == false)
             {
                 Thread.BeginCriticalRegion();
                 executing = false;
                 Thread.EndCriticalRegion();
                 break;
             }
             //binary.AddLast(binaryCode[pc++]);
             //byte[] nextWord = Program.Mem[(uint)pc];
             byte[] nextWord = cpu.ReadFromMemory((uint)pc);
             for (int i = 0; i < nextWord.Length; i++)
             {
                 binary.AddLast(nextWord[i]);
             }
             pc++;
             cpu.Constants.GetRegister("pc").Val = pc;
         }
         system.EndWorking();
         output.Text += DateTime.Now.ToString() + " Code executed successfully.\n";
         output.ScrollToCaret();
     }
     catch (System.Reflection.TargetInvocationException ex)
     {
         writeToOutput(DateTime.Now + " Execution error: " + ex.InnerException.Message + " in " + ex.InnerException.TargetSite + "\n");
         File.AppendAllText("error.txt", ex.ToString());
         StopDebugging();
         system.EndWorking();
         endExecution();
     }
     catch (Exception ex)
     {
         writeToOutput(DateTime.Now + " Execution error: " + ex.Message + "\n");
         File.AppendAllText("error.txt", ex.ToString());
         StopDebugging();
         system.EndWorking();
         endExecution();
     }
 }