Package edu.iu.jrsalata
Class ExtendedStatement
java.lang.Object
edu.iu.jrsalata.Statement
edu.iu.jrsalata.BaseStatement
edu.iu.jrsalata.ExtendedStatement
The ExtendedStatement class represents an extended statement in an assembler.
It extends the BaseStatement class and provides additional functionality for
handling extended format instructions, flags, and assembling the statement.
This class includes methods for setting various flags, managing arguments,
calculating displacement, and assembling the statement into its final form.
It also supports handling external symbols and creating modification records
when necessary.
Flags supported by this class include:
- nFlag: Indicates indirect addressing mode.
- iFlag: Indicates immediate addressing mode.
- xFlag: Indicates indexed addressing mode.
- bFlag: Indicates base relative addressing mode.
- pFlag: Indicates program counter relative addressing mode.
- eFlag: Indicates extended format (format 4) instruction.
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
stores each of the originally provided argsprotected String
contains the name of the base used in displacement calculationsprotected boolean
stores the b flagprotected boolean
stores the e flagprotected boolean
true if an external symbol is referenced, false if otherwiseprotected boolean
stores the i flagprotected String
Stores the needed modification record, if anyprotected boolean
stores the n flagprotected boolean
stores the p flagprotected boolean
stores the x flagFields inherited from class edu.iu.jrsalata.BaseStatement
format, location, opcode
Fields inherited from class edu.iu.jrsalata.Statement
block, controlSection, line, size
-
Constructor Summary
ConstructorDescriptionConstructs an ExtendedStatement object with default values.ExtendedStatement
(HexNum location, HexNum opcode, String args) Constructs an ExtendedStatement with the specified location, opcode, and arguments. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(VisitorInterface visitor) Accepts a visitor object and allows it to visit this instance of ExtendedStatement.assemble()
Assembles the statement into its object code representation.Retrieves the modification string.getSize()
Returns the size of the statement.void
Sets the string of args for this statementvoid
Sets the base of the statementvoid
setBFlag()
Sets the B flag to true.void
setEFlag()
Sets the eFlag to true.void
Marks this statement as having an external symbol.void
setPFlag()
Sets the pFlag to true.Methods inherited from class edu.iu.jrsalata.BaseStatement
getLocation, setLocation
Methods inherited from class edu.iu.jrsalata.Statement
getBlock, getControlSection, getLine, setBlock, setControlSection, setLine
-
Field Details
-
args
stores each of the originally provided args -
base
contains the name of the base used in displacement calculations -
modification
Stores the needed modification record, if any -
hasExternalSymbol
protected boolean hasExternalSymboltrue if an external symbol is referenced, false if otherwise -
nFlag
protected boolean nFlagstores the n flag -
iFlag
protected boolean iFlagstores the i flag -
xFlag
protected boolean xFlagstores the x flag -
bFlag
protected boolean bFlagstores the b flag -
pFlag
protected boolean pFlagstores the p flag -
eFlag
protected boolean eFlagstores the e flag
-
-
Constructor Details
-
ExtendedStatement
public ExtendedStatement()Constructs an ExtendedStatement object with default values. Initializes the arguments to "000", format to 3, and base to an empty string. Sets the size based on the format. -
ExtendedStatement
Constructs an ExtendedStatement with the specified location, opcode, and arguments.- Parameters:
location
- the memory location of the statementopcode
- the operation code of the statementargs
- the arguments for the statement
-
-
Method Details
-
setBFlag
public void setBFlag()Sets the B flag to true. -
setPFlag
public void setPFlag()Sets the pFlag to true. -
setEFlag
public void setEFlag()Sets the eFlag to true. -
setBase
Sets the base of the statement- Parameters:
base
- name of the base to be set
-
setExternalSymbol
public void setExternalSymbol()Marks this statement as having an external symbol. -
setArgs
Sets the string of args for this statement- Parameters:
args
- string of arguments the extended statement needs
-
getSize
Returns the size of the statement. If the eFlag is set, the size is incremented by 1. -
getModification
Retrieves the modification string.- Returns:
- the modification string.
-
accept
Accepts a visitor object and allows it to visit this instance of ExtendedStatement. This method is part of the Visitor design pattern. -
assemble
Assembles the statement into its object code representation.- Specified by:
assemble
in classStatement
- Returns:
- The assembled object code as a string.
- Throws:
InvalidAssemblyFileException
- If there is an error in the assembly process.
-