Next: Memory
Up: Hardware Components
Previous: Hardware Components
Contents
Index
- (CORE/PROCESSOR.JAVA,
- CORE/SAMPROCESSOR.JAVA)
The SaM processor is responsible for the loading of a Program object,
and the execution of Instruction objects, enclosed within that Program
object. Like a real processor, it also provides registers, which assist
program execution.
Program Execution
To execute a program, it must first be loaded by the processor. The
following methods allow this to happen:
- void init() - initialize the state of the processor
- void load(Program prog) - load a Program object into the processor
- Program getProgram() - obtain the current Program object
Following the successful loading of a program, it may be executed
one instruction at a time or all instructions with one call:
- void step() - Step executes one instruction.
- void run() - Run executes all instructions, until the HALT register
becomes nonzero
Registers
The SaM Processor implements several registers that allow the Processor
to execute programs. These are not used for data storage, but rather
are internal processor registers.
- HALT - Execution Status
Allowed Value: 0 (running) or 1 (stopped)
Start Value: 0
It is used to stop the execution of a program.
- PC - Program Counter
Allowed Value: 0 <= PC < Program Length
Start Value: 0
Used to track the instruction that will be executed next.
- SP - Stack Pointer
Allowed Value: 0 <= SP < Stack Limit
Start Value: 0
Used to track the first free memory location on the stack.
- FBR - Frame Based Register
Allowed Value: 0 <= FBR < Memory Limit
Start Value: 0
Used for relative addressing when constructing frames on the stack
Registers can be manipulated using the following methods:
- void set(int register, int value) - set a register to a given value
- int inc (int register) - increment a register by one, and return the
result
- int dec (int register) - decrement a register by one, and return the
result
- int[] getRegisters() - obtain the register array
Next: Memory
Up: Hardware Components
Previous: Hardware Components
Contents
Index
David Levitan
2006-02-12