Lab 6 -- The Machine

It is time to put together all the components of the machine and actually use the machine to run assembly programs.

6.1 The Machine Interface

A complete machine has a memory unit, a processor, and an I/O unit. Our machine allows its clients access to these components and has two additional operations: step and run. The machine interface is:

public interface MachineI {
  MemoryI getMem ( );
  ProcessorI getProc ( );
  ioUnitI getIO ( );

  /**
   *  step fetches the next instruction and executes it
   *  @exception MachineE if an error occurs during the execution
   *  of the instruction
  **/
  void step ( ) throws MachineE;

/**
   *  run executes all instructions from the current one 
   *  until it encounters a HALT instruction
   *  @exception MachineE if an error occurs during the execution
   *  of one of the instructions
  **/
  void run ( ) throws MachineE;

}
The methods step and run start executing instructions from the current value of the program counter (PC). The method step executes exactly one instruction. The method run repeatedly executes instructions until it encounters a halt instruction. Since instructions are stored in memory, the first step in executing an instruction is to fetch it into the processor. You will find it useful to have a (private) method fetchInstruction that performs the following actions: The second step above is slightly problematic. Objects stored in memory are guaranteed to be Word objects, but the IR requires something stronger: it requires an Instruction object. In other words, when we fetch a word from memory we must check if this word is an instruction. If not, we raise an exception. An excerpt of the code you need is:
if (currentWord instanceof Instruction) {
	Instruction currentIns = (Instruction)currentWord;
 	...
}
else throw new MemoryE ("Can only fetch instructions into the IR");

Note:
In order for you Machine program to correctly execute the current instruction, you will need to add an abstract execute method to your Instruction class.

6.2 Exercise

The help files for this exercise are at the URL http://www.cs.uoregon.edu/~sabry/duckMachine/machine/ and include:

Here is what you should do for this lab:


Visited times since March 23, 1999 (or the last crash).

Last modified: 05/05/99 18:07:25

yreimer@cs.uoregon.edu