Package mars.mips.instructions
Class BasicInstruction
java.lang.Object
mars.mips.instructions.Instruction
mars.mips.instructions.BasicInstruction
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
-
Field Summary
Fields inherited from class mars.mips.instructions.Instruction
BYTES_PER_INSTRUCTION, INSTRUCTION_LENGTH_BITS
-
Constructor Summary
ConstructorsConstructorDescriptionBasicInstruction
(String mnemonic, List<OperandType> operandTypes, InstructionFormat format, boolean isCTI, String title, String description, String encoding, SimulationFunction function) Create a newBasicInstruction
. -
Method Summary
Modifier and TypeMethodDescriptiondecodeOperands
(int binary) int
encodeOperands
(List<Operand> operands) Get the 32-character operation mask.Get the operand format of the instruction.int
int
int
Get length in bytes that this instruction requires in its binary form.boolean
Methods inherited from class mars.mips.instructions.Instruction
acceptsOperands, acceptsOperandsLoosely, formatOperands, formatSyntax, generateExampleOperands, getAlignedExampleSyntax, getDescription, getExampleOperands, getExampleSyntax, getMnemonic, getOperandTypes, getTitle
-
Constructor Details
-
BasicInstruction
public BasicInstruction(String mnemonic, List<OperandType> operandTypes, InstructionFormat format, boolean isCTI, String title, String description, String encoding, SimulationFunction function) Create a newBasicInstruction
.- 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 characters0
and1
indicate bit values that are part of the opcode, funct, etc. used to identify the instruction; the charactersf
(first),s
(second), andt
(third) are used to indicate bits derived from the respective operands.function
- The implementation of the instruction logic for simulation purposes.- Throws:
IllegalArgumentException
- Thrown ifencoding
is not a valid encoding descriptor string.
-
-
Method Details
-
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
- Returns:
-
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 classInstruction
- Returns:
- int length in bytes of corresponding binary instruction(s).
-
encodeOperands
- Parameters:
operands
-- Returns:
-
decodeOperands
- Parameters:
binary
-- Returns:
-