/** * The processor is responsible for stepping through * instructions, and manipulating the stack and registers. */ public interface Processor { /** * Loads the program that the processor must execute * @param prog The program to execute */ void load(Program prog); /** * Returns the program that is currently in memory to be executed * @return the program */ Program getProgram(); /** * Executes one instruction. If the program has * ended after this step, HALT is set. If step() * is called again after this, it will throw an * exception * @throws SystemException if there was an error during execution */ void step() throws SystemException; /** * Execute the whole program. This function * will block until the full program has executed, * therefore it's a bad idea to use it unless you're * sure the program will run successfully. * @throws SystemException if there's an error during execution */ void run() throws SystemException; /** * The program counter */ final static byte PC = 0; /** * The stack pointer */ final static byte SP = 1; /** * The heap pointer */ final static byte HP = 2; /** * The frame base register */ final static byte FBR = 3; /** * The halt register **/ final static byte HALT = 4; /** * Resets all the registers and the stack */ void reset(); /** * Returns the register value requested */ int get(byte register); /** * Returns a new copy of the register array. */ int[] getRegisters(); /** * Set value of the register * @throws SystemException if there is an error */ void set(byte register, int value) throws SystemException; /** * Increments the register and returns the new value. * @throws SystemException if there is an error */ int inc(byte register) throws SystemException; /** * Decrements the register and returns the new value. * @throws SystemException if there is an error */ int dec(byte register) throws SystemException; }