Package mars
Class ProgramStatement
java.lang.Object
mars.ProgramStatement
Represents one assembly/machine statement. This represents the "bare machine"
level. Pseudo-instructions have already been processed at this point and each
assembly statement generated by them is one of these.
- Version:
- August 2003
- Author:
- Pete Sanderson and Jason Bumgarner
-
Constructor Summary
ConstructorsConstructorDescriptionProgramStatement(int binaryStatement, int textAddress)
Constructor for ProgramStatement used only for writing a binary machine instruction with no source code to refer back to.ProgramStatement(MIPSprogram sourceMIPSprogram, String source, TokenList origTokenList, TokenList strippedTokenList, Instruction inst, int textAddress, int sourceLine)
Constructor for ProgramStatement when there are links back to all source and token information. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Given specification of BasicInstruction for this operator, build the corresponding assembly statement in basic assembly format (e.g. substituting register numbers for register names, replacing labels by values).void
Given the current statement in Basic Assembly format (see above), build the 32-bit binary machine code statement.int
Produces Text Segment address where the binary machine statement is stored.Produces Basic Assembly statement for this MIPS source statement.int
Produces 32-bit binary machine statement as int.Produces Instruction object corresponding to this statement's operator.Produces binary machine statement as 32 character string, all '0' and '1' chars.int
getOperand(int i)
Produces operand value from given array position (first operand is position 0).int[]
Produces int array of operand values for this statement.Produces token list generated from original source statement.Produces printable Basic Assembly statement for this MIPS source statement.Produces MIPS source statement.Produces String name of the source file containing this statement.int
Produces line number of MIPS source statement.Produces MIPSprogram object representing the source file containing this statement.Produces token list stripped of all but operator and operand tokens.void
setBasicAssemblyStatement(String statement)
Assigns given String to be Basic Assembly statement equivalent to this source line.void
setBinaryStatement(int binaryCode)
Assigns given int to be binary machine code equivalent to this source line.void
setMachineStatement(String statement)
Assigns given String to be binary machine code (32 characters, all of them 0 or 1) equivalent to this source line.void
associates MIPS source statement.toString()
Crude attempt at building String representation of this complex structure.
-
Constructor Details
-
ProgramStatement
public ProgramStatement(MIPSprogram sourceMIPSprogram, String source, TokenList origTokenList, TokenList strippedTokenList, Instruction inst, int textAddress, int sourceLine)Constructor for ProgramStatement when there are links back to all source and token information. These can be used by a debugger later on.- Parameters:
sourceMIPSprogram
- The MIPSprogram object that contains this statementsource
- The corresponding MIPS source statement.origTokenList
- Complete list of Token objects (includes labels, comments, parentheses, etc)strippedTokenList
- List of Token objects with all but operators and operands removed.inst
- The Instruction object for this statement's operator.textAddress
- The Text Segment address in memory where the binary machine code for this statement is stored.
-
ProgramStatement
public ProgramStatement(int binaryStatement, int textAddress)Constructor for ProgramStatement used only for writing a binary machine instruction with no source code to refer back to. Originally supported only NOP instruction (all zeroes), but extended in release 4.4 to support all basic instructions. This was required for the self-modifying code feature.- Parameters:
binaryStatement
- The 32-bit machine code.textAddress
- The Text Segment address in memory where the binary machine code for this statement is stored.
-
-
Method Details
-
buildBasicStatementFromBasicInstruction
Given specification of BasicInstruction for this operator, build the corresponding assembly statement in basic assembly format (e.g. substituting register numbers for register names, replacing labels by values).- Parameters:
errors
- The list of assembly errors encountered so far. May add to it here.
-
buildMachineStatementFromBasicStatement
Given the current statement in Basic Assembly format (see above), build the 32-bit binary machine code statement.- Parameters:
errors
- The list of assembly errors encountered so far. May add to it here.
-
toString
Crude attempt at building String representation of this complex structure. -
setBasicAssemblyStatement
Assigns given String to be Basic Assembly statement equivalent to this source line.- Parameters:
statement
- A String containing equivalent Basic Assembly statement.
-
setMachineStatement
Assigns given String to be binary machine code (32 characters, all of them 0 or 1) equivalent to this source line.- Parameters:
statement
- A String containing equivalent machine code.
-
setBinaryStatement
public void setBinaryStatement(int binaryCode)Assigns given int to be binary machine code equivalent to this source line.- Parameters:
binaryCode
- An int containing equivalent binary machine code.
-
setSource
associates MIPS source statement. Used by assembler when generating basic statements during macro expansion of extended statement.- Parameters:
src
- a MIPS source statement.
-
getSourceMIPSprogram
Produces MIPSprogram object representing the source file containing this statement.- Returns:
- The MIPSprogram object. May be null...
-
getSourceFile
Produces String name of the source file containing this statement.- Returns:
- The file name.
-
getSource
Produces MIPS source statement.- Returns:
- The MIPS source statement.
-
getSourceLine
public int getSourceLine()Produces line number of MIPS source statement.- Returns:
- The MIPS source statement line number.
-
getBasicAssemblyStatement
Produces Basic Assembly statement for this MIPS source statement. All numeric values are in decimal.- Returns:
- The Basic Assembly statement.
-
getPrintableBasicAssemblyStatement
Produces printable Basic Assembly statement for this MIPS source statement. This is generated dynamically and any addresses and values will be rendered in hex or decimal depending on the current setting.- Returns:
- The Basic Assembly statement.
-
getMachineStatement
Produces binary machine statement as 32 character string, all '0' and '1' chars.- Returns:
- The String version of 32-bit binary machine code.
-
getBinaryStatement
public int getBinaryStatement()Produces 32-bit binary machine statement as int.- Returns:
- The int version of 32-bit binary machine code.
-
getOriginalTokenList
Produces token list generated from original source statement.- Returns:
- The TokenList of Token objects generated from original source.
-
getStrippedTokenList
Produces token list stripped of all but operator and operand tokens.- Returns:
- The TokenList of Token objects generated by stripping original list of all except operator and operand tokens.
-
getInstruction
Produces Instruction object corresponding to this statement's operator.- Returns:
- The Instruction that matches the operator used in this statement.
-
getAddress
public int getAddress()Produces Text Segment address where the binary machine statement is stored.- Returns:
- address in Text Segment of this binary machine statement.
-
getOperands
public int[] getOperands()Produces int array of operand values for this statement.- Returns:
- int array of operand values (if any) required by this statement's operator.
-
getOperand
public int getOperand(int i)Produces operand value from given array position (first operand is position 0).- Parameters:
i
- Operand position in array (first operand is position 0).- Returns:
- Operand value at given operand array position. If < 0 or >= numOperands, it returns -1.
-