mars.simulator
Class Simulator

java.lang.Object
  |
  +--mars.simulator.Simulator

public class Simulator
extends java.lang.Object

Used to simulate the execution of an assembled MIPS program.


Field Summary
static int BREAKPOINT
          various reasons for simulate to end...
static int EXCEPTION
           
static int MAX_STEPS
           
static int NORMAL_TERMINATION
           
static int PAUSE_OR_STOP
           
 
Method Summary
static Simulator getInstance()
          Returns the Simulator object
 boolean simulate(MIPSprogram p, int pc, int maxSteps, int[] breakPoints, javax.swing.AbstractAction actor)
          Simulate execution of given MIPS program.
 void stopExecution(javax.swing.AbstractAction actor)
          Set the volatile stop boolean variable checked by the execution thread at the end of each MIPS instruction execution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BREAKPOINT

public static final int BREAKPOINT
various reasons for simulate to end...

See Also:
Constant Field Values

EXCEPTION

public static final int EXCEPTION
See Also:
Constant Field Values

MAX_STEPS

public static final int MAX_STEPS
See Also:
Constant Field Values

NORMAL_TERMINATION

public static final int NORMAL_TERMINATION
See Also:
Constant Field Values

PAUSE_OR_STOP

public static final int PAUSE_OR_STOP
See Also:
Constant Field Values
Method Detail

getInstance

public static Simulator getInstance()
Returns the Simulator object

Returns:
the Simulator object in use

simulate

public boolean simulate(MIPSprogram p,
                        int pc,
                        int maxSteps,
                        int[] breakPoints,
                        javax.swing.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(javax.swing.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.