Package mars.mips.instructions
Class ExtendedInstruction
java.lang.Object
mars.mips.instructions.Instruction
mars.mips.instructions.ExtendedInstruction
ExtendedInstruction represents a MIPS extended (a.k.a pseudo) instruction.
This assembly language instruction does not have a corresponding machine
instruction. Instead it is translated by the extended assembler into one or
more basic instructions (operations that have a corresponding machine
instruction). The TranslationCode object is responsible for performing the
translation.
- Version:
- August 2003
- Author:
- Pete Sanderson
-
Field Summary
Fields inherited from class mars.mips.instructions.Instruction
INSTRUCTION_LENGTH, INSTRUCTION_LENGTH_BITS, operandMask
-
Constructor Summary
ConstructorsConstructorDescriptionExtendedInstruction(String example, String translation)
Constructor for ExtendedInstruction, where no instruction description or compact translation is provided.ExtendedInstruction(String example, String translation, String description)
Constructor for ExtendedInstruction.ExtendedInstruction(String example, String translation, String compactTranslation, String description)
Constructor for ExtendedInstruction. -
Method Summary
Modifier and TypeMethodDescriptionGet ArrayList of Strings that represent list of templates for basic instructions generated by this extended instruction.Get ArrayList of Strings that represent list of templates for basic instructions generated by the "compact" or 16-bit version of this extended instruction.int
Get length in bytes that this extended instruction requires in its binary form if it includes an alternative expansion for compact memory (16 bit addressing) configuration.int
Get length in bytes that this extended instruction requires in its binary form.boolean
Determine whether or not this pseudo-instruction has a second translation optimized for 16 bit address space: a compact version.static String
makeTemplateSubstitutions(MIPSprogram program, String template, TokenList theTokenList)
Given a basic instruction template and the list of tokens from an extended instruction statement, substitute operands from the token list appropriately into the template to generate the basic statement.Methods inherited from class mars.mips.instructions.Instruction
getDescription, getExampleFormat, getName, getTokenList
-
Constructor Details
-
ExtendedInstruction
public ExtendedInstruction(String example, String translation, String compactTranslation, String description)Constructor for ExtendedInstruction.- Parameters:
example
- A String containing example use of the MIPS extended instruction.translation
- Specifications for translating this instruction into a sequence of one or more MIPS basic instructions.compactTranslation
- Alternative translation that can be used if running under a compact (16 bit) memory configuration.description
- A helpful description to be included on help requests The presence of an alternative "compact translation" can optimize code generation by assuming that data label addresses are 16 bits instead of 32
-
ExtendedInstruction
Constructor for ExtendedInstruction. No compact translation is provided.- Parameters:
example
- A String containing example use of the MIPS extended instruction.translation
- Specifications for translating this instruction into a sequence of one or more MIPS basic instructions.description
- a helpful description to be included on help requests
-
ExtendedInstruction
Constructor for ExtendedInstruction, where no instruction description or compact translation is provided.- Parameters:
example
- A String containing example use of the MIPS extended instruction.translation
- Specifications for translating this instruction into a sequence of one or more MIPS basic instructions.
-
-
Method Details
-
getInstructionLength
public int getInstructionLength()Get length in bytes that this extended instruction requires in its binary form. The answer depends on how many basic instructions it expands to. This may vary, if expansion includes a nop, depending on whether or not delayed branches are enabled. Each requires 4 bytes.- Overrides:
getInstructionLength
in classInstruction
- Returns:
- int length in bytes of corresponding binary instruction(s).
-
getBasicIntructionTemplateList
Get ArrayList of Strings that represent list of templates for basic instructions generated by this extended instruction.- Returns:
- ArrayList of Strings.
-
getCompactInstructionLength
public int getCompactInstructionLength()Get length in bytes that this extended instruction requires in its binary form if it includes an alternative expansion for compact memory (16 bit addressing) configuration. The answer depends on how many basic instructions it expands to. This may vary, if expansion includes a nop, depending on whether or not delayed branches are enabled. Each requires 4 bytes.- Returns:
- int length in bytes of corresponding binary instruction(s). Returns 0 if an alternative expansion is not defined for this instruction.
-
hasCompactTranslation
public boolean hasCompactTranslation()Determine whether or not this pseudo-instruction has a second translation optimized for 16 bit address space: a compact version. -
getCompactBasicIntructionTemplateList
Get ArrayList of Strings that represent list of templates for basic instructions generated by the "compact" or 16-bit version of this extended instruction.- Returns:
- ArrayList of Strings. Returns null if the instruction does not have a compact alternative.
-
makeTemplateSubstitutions
public static String makeTemplateSubstitutions(MIPSprogram program, String template, TokenList theTokenList)Given a basic instruction template and the list of tokens from an extended instruction statement, substitute operands from the token list appropriately into the template to generate the basic statement. Assumes the extended instruction statement has been translated from source form to basic assembly form (e.g. register mnemonics translated to corresponding register numbers). Operand format of source statement is already verified correct. Assume the template has correct number and positions of operands. Template is String with special markers. In the list below, n represents token position (1,2,3,etc) in source statement (operator is token 0, parentheses count but commas don't):- RGn means substitute register found in n'th token of source statement
- NRn means substitute next higher register than the one in n'th token of source code
- OPn means substitute n'th token of source code as is
- LLn means substitute low order 16 bits from label address in source token n.
- LLnU means substitute low order 16 bits (unsigned) from label address in source token n.
- LLnPm (m=1,2,3,4) means substitute low order 16 bits from label address in source token n, after adding m.
- LHn means substitute high order 16 bits from label address in source token n. Must add 1 if address bit 15 is 1.
- LHnPm (m=1,2,3,4) means substitute high order 16 bits from label address in source token n, after adding m. Must then add 1 if bit 15 is 1.
- VLn means substitute low order 16 bits from 32 bit value in source token n.
- VLnU means substitute low order 16 bits (unsigned) from 32 bit value in source token n.
- VLnPm (m=1,2,3,4) means substitute low order 16 bits from 32 bit value in source token n, after adding m to value.
- VLnPmU (m=1,2,3,4) means substitute low order 16 bits (unsigned) from 32 bit value in source token n, after adding m to value.
- VHLn means substitute high order 16 bits from 32 bit value in source token n. Use this if later combined with low order 16 bits using "ori $1,$1,VLn". See logical and branch operations.
- VHn means substitute high order 16 bits from 32 bit value in source token n, then add 1 if value's bit 15 is 1. Use this only if later instruction uses VLn($1) to calculate 32 bit address. See loads and stores.
- VHLnPm (m=1,2,3,4) means substitute high order 16 bits from 32 bit value in source token n, after adding m. See VHLn.
- VHnPm (m=1,2,3,4) means substitute high order 16 bits from 32 bit value in source token n, after adding m. Must then add 1 if bit 15 is 1. See VHn.
- LLP is similar to LLn, but is needed for "label+100000" address offset. Immediate is added before taking low order 16.
- LLPU is similar to LLnU, but is needed for "label+100000" address offset. Immediate is added before taking low order 16 (unsigned).
- LLPPm (m=1,2,3,4) is similar to LLP except m is added along with mmediate before taking low order 16.
- LHPA is similar to LHn, but is needed for "label+100000" address offset. Immediate is added before taking high order 16.
- LHPN is similar to LHPA, used only by "la" instruction. Address resolved by "ori" so do not add 1 if bit 15 is 1.
- LHPAPm (m=1,2,3,4) is similar to LHPA except value m is added along with immediate before taking high order 16.
- LHL means substitute high order 16 bits from label address in token 2 of "la" (load address) source statement.
- LAB means substitute textual label from last token of source statement. Used for various branches.
- S32 means substitute the result of subtracting the constant value in last token from 32. Used by "ror", "rol".
- DBNOP means Delayed Branching NOP - generate a "nop" instruction but only if delayed branching is enabled. Added in 3.4.1 release.
- BROFFnm means substitute n if delayed branching is NOT enabled otherwise substitute m. n and m are single digit numbers indicating constant branch offset (in words). Added in 3.4.1 release.
- Parameters:
template
- a String containing template for basic statement.theTokenList
- a TokenList containing tokens from extended instruction.- Returns:
- String representing basic assembler statement.
-