mars.simulator
Class Simulator

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

public class Simulator
extends Observable

Used to simulate the execution of an assembled MIPS program.

Author:
Pete Sanderson

Nested Class Summary
static interface Simulator.StopListener
           
 
Field Summary
static int BREAKPOINT
          various reasons for simulate to end...
static int CLIFF_TERMINATION
           
static int EXCEPTION
           
static int externalInterruptingDevice
           
static int MAX_STEPS
           
static int NO_DEVICE
           
static int NORMAL_TERMINATION
           
static int PAUSE_OR_STOP
           
 
Method Summary
 void addStopListener(Simulator.StopListener l)
           
static Simulator getInstance()
          Returns the Simulator object
static boolean inDelaySlot()
          Determine whether or not the next instruction to be executed is in a "delay slot".
 void removeStopListener(Simulator.StopListener l)
           
 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, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_DEVICE

public static final int NO_DEVICE
See Also:
Constant Field Values

externalInterruptingDevice

public static volatile int externalInterruptingDevice

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

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 Detail

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)