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.
Version:
August 2003
Author:
Pete Sanderson and Ken Vollmar
  • Field Details

    • 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.
  • Constructor Details

    • Instruction

      public Instruction()
  • Method Details

    • 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).