Class Simulator

java.lang.Object
java.util.Observable
mars.simulator.Simulator

public class Simulator extends Observable
Used to simulate the execution of an assembled MIPS program.
Version:
August 2005
Author:
Pete Sanderson
  • Field Details

  • Method Details

    • getInstance

      public static Simulator getInstance()
      Returns the Simulator object
      Returns:
      the Simulator object in use
    • inDelaySlot

      public static boolean inDelaySlot()
      Determine whether or not the next instruction to be executed is in a "delay slot". This means delayed branching is enabled, the branch condition has evaluated true, and the next instruction executed will be the one following the branch. It is said to occupy the "delay slot." Normally programmers put a nop instruction here but it can be anything.
      Returns:
      true if next instruction is in delay slot, false otherwise.
    • simulate

      public boolean simulate(MIPSprogram p, int pc, int maxSteps, int[] breakPoints, AbstractAction actor) throws ProcessingException
      Simulate execution of given MIPS program. It must have already been assembled.
      Parameters:
      p - The MIPSprogram to be simulated.
      pc - address of first instruction to simulate; this goes into program counter
      maxSteps - maximum number of steps to perform before returning false (0 or less means no max)
      breakPoints - array of breakpoint program counter values, use null if none
      actor - the GUI component responsible for this call, usually GO or STEP. null if none.
      Returns:
      true if execution completed, false otherwise
      Throws:
      ProcessingException - Throws exception if run-time exception occurs.
    • stopExecution

      public void stopExecution(AbstractAction actor)
      Set the volatile stop boolean variable checked by the execution thread at the end of each MIPS instruction execution. If variable is found to be true, the execution thread will depart gracefully so the main thread handling the GUI can take over. This is used by both STOP and PAUSE features.
    • addStopListener

      public void addStopListener(Simulator.StopListener l)
    • removeStopListener

      public void removeStopListener(Simulator.StopListener l)