## mars.mips.instructions
Class Instruction

    java.lang.Object
      mars.mips.instructions.Instruction

Direct Known Subclasses:
  BasicInstruction, ExtendedInstruction

    public abstract class Instruction

extends Object

Base class to represent member of MIPS instruction set.

Author:
  Pete Sanderson and Ken Vollmar

Field Summary
`protected String` `description` Description of instruction for display to user
`protected String` `exampleFormat` Example usage of this instruction.
`static int` `INSTRUCTION_LENGTH` Length in bytes of a machine instruction.
`static int` `INSTRUCTION_LENGTH_BITS`
`protected String` `mnemonic` The instruction name.
`static char[]` `operandMask` Characters used in instruction mask to indicate bit positions for 'f'irst, 's'econd, and 't'hird operands.
`protected TokenList` `tokenList` List of tokens generated by tokenizing example usage (see `exampleFormat`).

Constructor Summary
`Instruction()`

Method Summary
`protected void` `createExampleTokenList()` Used to build a token list from the example instruction provided as constructor argument.
`protected String` `extractOperator(String example)` Used by subclass constructors to extract operator mnemonic from the instruction example.
`String` `getDescription()` Get string describing the instruction.
`String` `getExampleFormat()` Get string descriptor of instruction's format.
`int` `getInstructionLength()` Get length in bytes that this instruction requires in its binary form.
`String` `getName()` Get operation mnemonic
`TokenList` `getTokenList()` Get TokenList corresponding to correct instruction syntax.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### INSTRUCTION_LENGTH

    public static final int INSTRUCTION_LENGTH

  Length in bytes of a machine instruction. MIPS is a RISC architecture so all instructions are the same length. Currently set to 4.

  See Also:
    Constant Field Values

### INSTRUCTION_LENGTH_BITS

    public static final int INSTRUCTION_LENGTH_BITS

See Also:
  Constant Field Values

### operandMask

    public static char[] operandMask

  Characters used in instruction mask to indicate bit positions for 'f'irst, 's'econd, and 't'hird operands.

### mnemonic

    protected String mnemonic

  The instruction name.

### exampleFormat

    protected String exampleFormat

  Example usage of this instruction. Is provided as subclass constructor argument.

### description

    protected String description

  Description of instruction for display to user

### tokenList

    protected TokenList tokenList

  List of tokens generated by tokenizing example usage (see `exampleFormat`).

Constructor Detail

### Instruction

    public Instruction()

Method Detail

### getName

    public String getName()

  Get operation mnemonic

  Returns:
    operation mnemonic (e.g. addi, sw)

### getExampleFormat

    public String getExampleFormat()

  Get string descriptor of instruction's format. This is an example MIPS assembler instruction usage which contains the operator and all operands. Operands are separated by commas, an operand that begins with a '$' represents a register, and an integer operand represents an immediate value or address. Here are two examples: "nor $1,$2,$3" and "sw $1,100($2)"

  Returns:
    String representing example instruction format.

### getDescription

    public String getDescription()

  Get string describing the instruction. This is not used internally by MARS, but is for display to the user.

  Returns:
    String describing the instruction.

### getTokenList

    public TokenList getTokenList()

  Get TokenList corresponding to correct instruction syntax. For example, the instruction with format "sw $1,100($2)" yields token list <operator><register_number><integer><left_paren><register_number><right_parent>

  Returns:
    TokenList object representing correct instruction usage.

### getInstructionLength

    public int getInstructionLength()

  Get length in bytes that this instruction requires in its binary form. Default is 4 (holds for all basic instructions), but can be overridden in subclass.

  Returns:
    int length in bytes of corresponding binary instruction(s).

### extractOperator

    protected String extractOperator(String example)

  Used by subclass constructors to extract operator mnemonic from the instruction example.

### createExampleTokenList

    protected void createExampleTokenList()

  Used to build a token list from the example instruction provided as constructor argument. Parser uses this for syntax checking.