mars.mips.instructions
Class ExtendedInstruction

java.lang.Object
  |
  +--mars.mips.instructions.Instruction
        |
        +--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.


Field Summary
 
Fields inherited from class mars.mips.instructions.Instruction
description, exampleFormat, INSTRUCTION_LENGTH, INSTRUCTION_LENGTH_BITS, mnemonic, operandMask, tokenList
 
Constructor Summary
ExtendedInstruction(java.lang.String example, java.lang.String translation)
          Constructor for ExtendedInstruction, where no instruction description is provided.
ExtendedInstruction(java.lang.String example, java.lang.String translation, java.lang.String description)
          Constructor for ExtendedInstruction.
 
Method Summary
 java.util.ArrayList getBasicIntructionTemplateList()
          Get ArrayList of Strings that represent list of templates for basic instructions generated by this extended instruction.
 int getInstructionLength()
          Get length in bytes that this extended instruction requires in its binary form.
static java.lang.String makeTemplateSubstitutions(MIPSprogram program, java.lang.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(java.lang.String example,
                           java.lang.String translation,
                           java.lang.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.
description - a helpful description to be included on help requests

ExtendedInstruction

public ExtendedInstruction(java.lang.String example,
                           java.lang.String translation)
Constructor for ExtendedInstruction, where no instruction description 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. Each requires 4 bytes.

Overrides:
getInstructionLength in class Instruction
Returns:
int length in bytes of corresponding binary instruction(s).

getBasicIntructionTemplateList

public java.util.ArrayList getBasicIntructionTemplateList()
Get ArrayList of Strings that represent list of templates for basic instructions generated by this extended instruction.

Returns:
ArrayList of Strings.

makeTemplateSubstitutions

public static java.lang.String makeTemplateSubstitutions(MIPSprogram program,
                                                         java.lang.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.
Returns:
String representing basic assembler statement.