Hardware machines have a built-in set of instructions that they can decode and execute. We now study how to extend our implementation with representations of the machine instructions.
The instruction set of the machine is in Table 4.1 (see p. 204 of the book).
Binary opcode | Decimal opcode | Operation (X is a machine address) |
---|---|---|
LOAD X | ||
STORE X | ||
CLEAR X | ||
ADD X | ||
INCREMENT X | ||
SUBTRACT X | ||
DECREMENT X | ||
COMPARE X | ||
JUMP X | ||
JUMPGT X | ||
JUMPEQ X | ||
JUMPLT X | ||
JUMPNEQ X | ||
IN X | ||
OUT X | ||
HALT |
To extend our implementation of the machine, the first step is to write Java definitions for the instructions. Since we will need to distinguish the instructions from each other, we will have a separate class for each instruction. Recall that the Instruction
class is a subclass of the Word
class, just as Data
and Address
are subclasses of the Word
class. Your job is to design and implement 16 different classes, one for each machine instruction. Each of these 16 different classes representing machine instructions should be a subclass of the Instruction
class.
E.g. A possible hierarchy might look like:
Word | ------------------- | | | Data Address Instruction | ----------------------------------- | | | LoadIns StoreIns ClearIns . . .Feel free to add additional levels to the hierarchy for your convenience.
Instruction
class must be a subclass of the Word
class.
Instruction
class,
For example, if we have instruction CLEAR and address 17, then:
32 bit opcode for CLEAR instruction: 32 bit address (integer 17): 00000000000000000000000000000010 00000000000000000000000000010001
new 32 bit number 00100000000000000000000000010001
Note that the new 32 bit number evaluates to 536870929, so this is the integer that should be returned from the toInt method in this example.
Turn in the code for the machine instruction classes during class on Monday, May 3rd.
Last modified: 04/21/99 09:38:25
yreimer@cs.uoregon.edu