edu.cornell.cs.sam.core
Interface Processor

All Known Implementing Classes:
SamProcessor

public interface Processor

The processor is responsible for stepping through instructions, and manipulating the stack and registers.


Field Summary
static int FBR
          The frame base register - points to the base of the current function frame
static int HALT
          The halt register - set to one to stop the processor
static int PC
          The program counter - contains the address of the instruction to be executed next
static int SP
          The stack pointer - points to the first free location on the stack
 
Method Summary
 int dec(int register)
          Decrements the register and returns the new value.
 int get(int register)
          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 register)
          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 register, int value)
          Set value of the register
 void step()
          Executes one instruction.
 void verify(int register, int value)
          Verifies if the value is valid for this registers and throws an exception if not.
 

Field Detail

PC

static final int PC
The program counter - contains the address of the instruction to be executed next

See Also:
Constant Field Values

SP

static final int SP
The stack pointer - points to the first free location on the stack

See Also:
Constant Field Values

FBR

static final int FBR
The frame base register - points to the base of the current function frame

See Also:
Constant Field Values

HALT

static final int HALT
The halt register - set to one to stop the processor

See Also:
Constant Field Values
Method Detail

load

void load(Program prog)
          throws SystemException
Loads the program that the processor must execute

Parameters:
prog - The program to execute
Throws:
SystemException - if the program was not loaded successfully

getProgram

Program getProgram()
Returns the program that is currently in memory to be executed

Returns:
The program currently executing

getSystem

Sys getSystem()
Returns the system object of this processor

Returns:
The system object for the processor

step

void step()
          throws SystemException
Executes one instruction. If that instruction is HALT, the next invocation of step() without resetting the processor will throw an exception.

Throws:
SystemException - if there is an error during execution

run

void run()
         throws SystemException
Execute the whole program. This function will block until the full program has executed,

Throws:
SystemException - if there is an error during execution

init

void init()
Initializes all registers to their initial state


get

int get(int register)
Returns the register value requested

Parameters:
register - The register to query
Returns:
The value of the queries register

getRegisters

int[] getRegisters()
Returns a new copy of the register array.

Returns:
The array of registers

set

void set(int register,
         int value)
         throws SystemException
Set value of the register

Parameters:
register - The register to set
value - The value to which to set the register
Throws:
SystemException - if the register value is invalid

inc

int inc(int register)
        throws SystemException
Increments the register and returns the new value.

Parameters:
register - The register to increment
Returns:
The incremented register
Throws:
SystemException - if the resulting register value is invalid

dec

int dec(int register)
        throws SystemException
Decrements the register and returns the new value.

Parameters:
register - The register to decrement
Returns:
The decremented register
Throws:
SystemException - if the resulting register value is invalid

verify

void verify(int register,
            int value)
            throws SystemException
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.

Parameters:
register - The register to verify
value - The value to verify
Throws:
SystemException - if the value is invalid for this register