Class BasicInstruction

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

public class BasicInstruction extends Instruction
Class to represent a basic instruction in the MIPS instruction set. Basic instruction means it translates directly to a 32-bit binary machine instruction.
Version:
August 2003
Author:
Pete Sanderson and Ken Vollmar
  • Constructor Details

    • BasicInstruction

      public BasicInstruction(String mnemonic, List<OperandType> operandTypes, InstructionFormat format, boolean isCTI, String title, String description, String encoding, SimulationFunction function)
      Create a new BasicInstruction.
      Parameters:
      mnemonic - The instruction mnemonic used in assembly code (case-insensitive).
      operandTypes - The list of operand types for this instruction, which is used to select a specific instruction from the group of instructions sharing a mnemonic.
      format - The general organization of this instruction's binary encoding, as interpreted by hardware.
      isCTI - true if this is a Control Transfer Instruction (CTI), that is, a branch, jump, or similar instruction that alters the Program Counter; false otherwise.
      title - The "long name" of this instruction, which should relate to the mnemonic.
      description - A short human-readable description of what this instruction does when executed.
      encoding - A string describing the binary encoding for this instruction, with each character representing one bit (although spaces may be used as visual separators). The characters 0 and 1 indicate bit values that are part of the opcode, funct, etc. used to identify the instruction; the characters f (first), s (second), and t (third) are used to indicate bits derived from the respective operands.
      function - The implementation of the instruction logic for simulation purposes.
      Throws:
      IllegalArgumentException - Thrown if encoding is not a valid encoding descriptor string.
  • Method Details

    • getFormat

      public InstructionFormat getFormat()
      Get the operand format of the instruction. MIPS defines 3 of these R-format, I-format, and J-format. R-format is all registers. I-format is address formed from register base with immediate offset. J-format is for jump destination addresses. I have added one more: I-branch-format, for branch destination addresses. These are a variation of the I-format in that the computed value is address relative to the Program Counter. All four formats are represented by static objects.
      Returns:
      The machine instruction format, R, I, J or I-branch.
    • isControlTransferInstruction

      public boolean isControlTransferInstruction()
    • getFunction

      public SimulationFunction getFunction()
      Returns:
    • getEncodingDescriptor

      public String getEncodingDescriptor()
      Get the 32-character operation mask. Each mask position represents a bit position in the 32-bit machine instruction. Operation codes and unused bits are represented in the mask by 1's and 0's. Operand codes are represented by 'f', 's', and 't' for bits occupied by first, secon and third operand, respectively.
      Returns:
      The 32 bit mask, as a String
    • getOperationMask

      public int getOperationMask()
      Returns:
    • getOperationKey

      public int getOperationKey()
      Returns:
    • getSizeBytes

      public int getSizeBytes()
      Get length in bytes that this instruction requires in its binary form.
      Specified by:
      getSizeBytes in class Instruction
      Returns:
      int length in bytes of corresponding binary instruction(s).
    • encodeOperands

      public int encodeOperands(List<Operand> operands)
      Parameters:
      operands -
      Returns:
    • decodeOperands

      public List<Operand> decodeOperands(int binary)
      Parameters:
      binary -
      Returns: