Package mars.simulator
Class Simulator
java.lang.Object
java.util.Observable
mars.simulator.Simulator
Used to simulate the execution of an assembled MIPS program.
- Version:
- August 2005
- Author:
- Pete Sanderson
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
various reasons for simulate to end...static int
static int
static int
static int
static int
static int
static int
-
Method Summary
Modifier and TypeMethodDescriptionvoid
static Simulator
Returns the Simulator objectstatic boolean
Determine whether or not the next instruction to be executed is in a "delay slot".void
boolean
simulate(MIPSprogram p, int pc, int maxSteps, int[] breakPoints, AbstractAction actor)
Simulate execution of given MIPS program.void
stopExecution(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.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
-
Field Details
-
NO_DEVICE
public static final int NO_DEVICE- See Also:
- Constant Field Values
-
externalInterruptingDevice
public static volatile int externalInterruptingDevice -
BREAKPOINT
public static final int BREAKPOINTvarious 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
-
CLIFF_TERMINATION
public static final int CLIFF_TERMINATION- See Also:
- Constant Field Values
-
PAUSE_OR_STOP
public static final int PAUSE_OR_STOP- See Also:
- Constant Field Values
-
-
Method Details
-
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 ProcessingExceptionSimulate 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 countermaxSteps
- 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 noneactor
- 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
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
-
removeStopListener
-