Package mars.mips.instructions
Class Instruction
java.lang.Object
mars.mips.instructions.Instruction
- Direct Known Subclasses:
BasicInstruction
,ExtendedInstruction
Base class to represent member of MIPS instruction set.
- Version:
- August 2003
- Author:
- Pete Sanderson and Ken Vollmar
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
Length in bytes of a machine instruction.static int
static char[]
Characters used in instruction mask to indicate bit positions for 'f'irst, 's'econd, and 't'hird operands. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet string describing the instruction.Get string descriptor of instruction's format.int
Get length in bytes that this instruction requires in its binary form.getName()
Get operation mnemonicGet TokenList corresponding to correct instruction syntax.
-
Field Details
-
INSTRUCTION_LENGTH
public static final int INSTRUCTION_LENGTHLength 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[] operandMaskCharacters 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
Get operation mnemonic- Returns:
- operation mnemonic (e.g. addi, sw)
-
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
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
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).
-