next up previous contents index
Next: SaM Symbol Table Up: Internal Simulator Classes Previous: Internal Simulator Classes   Contents   Index

SaM Instructions

(CORE/INSTRUCTIONS/*)
 
A SaM Instruction is a class, implementing the Instruction interface. The exec() method manipulates the hardware components of the SaM system and must be overwritten by all instructions. All instructions are expected to manually change the PC register, either incrementing it in the case of most instructions, or changing its value to a new value for a jump instruction. See section sec:SAM-Instruction-Set for the SaM Instruction Set Manual.

Every instruction is represented as its own class, all of which extend SamInstruction or one of its subclasses. An instruction that extends SamInstruction is one that does not have any operands. Instructions that need an operand extend one of the subclasses of SamInstruction - SamIntInstruction, SamFloatInstruction, SamCharInstruction, etc... These subclasses provide the op variable in the appropriate type which is set to the operand provided to the instruction. All included instructions are prefixed by SAM_, which is removed automatically when the instruction is actually used.

Instructions do not check the types of any input values they use. In the default SamProcessor implementation, floats, for example, are stored as integers using standard Java float->integer conversion routines. An integer operation that is given a float as input will produce unexpected results. Some instructions, such as ADD, SUB, DUP, SWAP, ISNIL, NOT and EQUALS are defined on multiple data types. Refer to the ISA manual for details.

Apart from the op variable, which is provided to operand classes, instructions also have access to the cpu (the processor), mem (the memory), video (the video interface), sys (the system object), and prog (the program that the instruction is a part of).

Creating a new Instruction

To create a new instruction:

  1. Decide whether your instruction needs an operand, and select the approriate class to extend.
  2. Create a new class definition that inherits the class you have selected.
  3. Override the exec() method
Things to remember:


next up previous contents index
Next: SaM Symbol Table Up: Internal Simulator Classes Previous: Internal Simulator Classes   Contents   Index
David Levitan 2006-02-12