mars.mips.instructions
Class ExtendedInstruction

java.lang.Object
  extended by mars.mips.instructions.Instruction
      extended by mars.mips.instructions.ExtendedInstruction

public class ExtendedInstruction
extends Instruction

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.

Author:
Pete Sanderson

Field Summary
 
Fields inherited from class mars.mips.instructions.Instruction
description, exampleFormat, INSTRUCTION_LENGTH, INSTRUCTION_LENGTH_BITS, mnemonic, operandMask, tokenList
 
Constructor Summary
ExtendedInstruction(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
 ArrayList getBasicIntructionTemplateList()
          Get ArrayList of Strings that represent list of templates for basic instructions generated by this extended instruction.
 ArrayList 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.
 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.
 int getInstructionLength()
          Get length in bytes that this extended instruction requires in its binary form.
 boolean hasCompactTranslation()
          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
createExampleTokenList, extractOperator, getDescription, getExampleFormat, getName, getTokenList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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

public ExtendedInstruction(String example,
                           String translation,
                           String description)
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

public ExtendedInstruction(String example,
                           String translation)
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 Detail

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 class Instruction
Returns:
int length in bytes of corresponding binary instruction(s).

getBasicIntructionTemplateList

public ArrayList 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

public ArrayList 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):

Parameters:
template - a String containing template for basic statement.
tokenList - a TokenList containing tokens from extended instruction.
Returns:
String representing basic assembler statement.