edu.cornell.cs.sam.core
Class SamProcessor

java.lang.Object
  extended by edu.cornell.cs.sam.core.SamProcessor
All Implemented Interfaces:
Processor

public class SamProcessor
extends java.lang.Object
implements Processor

Implementation of a SaM Processor


Field Summary
static int REGISTERS
           
 
Fields inherited from interface edu.cornell.cs.sam.core.Processor
FBR, HALT, PC, SP
 
Constructor Summary
SamProcessor(Sys sys)
           
 
Method Summary
 int dec(int reg)
          Decrements the register and returns the new value.
 int get(int reg)
          Returns the register value requested
 Program getProgram()
          Returns the program that is currently in memory to be executed
 int[] getRegisters()
          Returns a new copy of the register array.
 Sys getSystem()
          Returns the system object of this processor
 int inc(int reg)
          Increments the register and returns the new value.
 void init()
          Initializes all registers to their initial state
 void load(Program prog)
          Loads the program that the processor must execute
 void run()
          Execute the whole program.
 void set(int reg, int value)
          Set value of the register
 void step()
          Executes one instruction.
 void verify(int reg, int value)
          Verifies if the value is valid for this registers and throws an exception if not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REGISTERS

public static final int REGISTERS
See Also:
Constant Field Values
Constructor Detail

SamProcessor

public SamProcessor(Sys sys)
Method Detail

getSystem

public Sys getSystem()
Description copied from interface: Processor
Returns the system object of this processor

Specified by:
getSystem in interface Processor
Returns:
The system object for the processor

load

public void load(Program prog)
          throws SystemException
Description copied from interface: Processor
Loads the program that the processor must execute

Specified by:
load in interface Processor
Parameters:
prog - The program to execute
Throws:
SystemException - if the program was not loaded successfully

getProgram

public Program getProgram()
Description copied from interface: Processor
Returns the program that is currently in memory to be executed

Specified by:
getProgram in interface Processor
Returns:
The program currently executing

step

public void step()
          throws SystemException
Description copied from interface: Processor
Executes one instruction. If that instruction is HALT, the next invocation of step() without resetting the processor will throw an exception.

Specified by:
step in interface Processor
Throws:
SystemException - if there is an error during execution

run

public void run()
         throws SystemException
Description copied from interface: Processor
Execute the whole program. This function will block until the full program has executed,

Specified by:
run in interface Processor
Throws:
SystemException - if there is an error during execution

init

public void init()
Description copied from interface: Processor
Initializes all registers to their initial state

Specified by:
init in interface Processor

get

public int get(int reg)
Description copied from interface: Processor
Returns the register value requested

Specified by:
get in interface Processor
Parameters:
reg - The register to query
Returns:
The value of the queries register

getRegisters

public int[] getRegisters()
Description copied from interface: Processor
Returns a new copy of the register array.

Specified by:
getRegisters in interface Processor
Returns:
The array of registers

set

public void set(int reg,
                int value)
         throws SystemException
Description copied from interface: Processor
Set value of the register

Specified by:
set in interface Processor
Parameters:
reg - The register to set
value - The value to which to set the register
Throws:
SystemException - if the register value is invalid

inc

public int inc(int reg)
        throws SystemException
Description copied from interface: Processor
Increments the register and returns the new value.

Specified by:
inc in interface Processor
Parameters:
reg - The register to increment
Returns:
The incremented register
Throws:
SystemException - if the resulting register value is invalid

dec

public int dec(int reg)
        throws SystemException
Description copied from interface: Processor
Decrements the register and returns the new value.

Specified by:
dec in interface Processor
Parameters:
reg - The register to decrement
Returns:
The decremented register
Throws:
SystemException - if the resulting register value is invalid

verify

public void verify(int reg,
                   int value)
            throws SystemException
Description copied from interface: Processor
Verifies if the value is valid for this registers and throws an exception if not. This is done internally as well, but this function is exposed to force a SystemException earlier.

Specified by:
verify in interface Processor
Parameters:
reg - The register to verify
value - The value to verify
Throws:
SystemException - if the value is invalid for this register