Class ExtendedStatement


public class ExtendedStatement extends BaseStatement
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.
Note: This class relies on the SymTable class for symbol table lookups and the HexNum class for handling hexadecimal numbers.
  • Field Details

    • args

      protected String args
      stores each of the originally provided args
    • base

      protected String base
      contains the name of the base used in displacement calculations
    • modification

      protected String modification
      Stores the needed modification record, if any
    • hasExternalSymbol

      protected boolean hasExternalSymbol
      true if an external symbol is referenced, false if otherwise
    • nFlag

      protected boolean nFlag
      stores the n flag
    • iFlag

      protected boolean iFlag
      stores the i flag
    • xFlag

      protected boolean xFlag
      stores the x flag
    • bFlag

      protected boolean bFlag
      stores the b flag
    • pFlag

      protected boolean pFlag
      stores the p flag
    • eFlag

      protected boolean eFlag
      stores 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

      public ExtendedStatement(HexNum location, HexNum opcode, String args)
      Constructs an ExtendedStatement with the specified location, opcode, and arguments.
      Parameters:
      location - the memory location of the statement
      opcode - the operation code of the statement
      args - 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

      public void setBase(String base)
      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

      public void setArgs(String args)
      Sets the string of args for this statement
      Parameters:
      args - string of arguments the extended statement needs
    • getSize

      public HexNum getSize()
      Returns the size of the statement. If the eFlag is set, the size is incremented by 1.
      Overrides:
      getSize in class Statement
      Returns:
      the size of the statement as a HexNum object. If eFlag is true, the size is incremented by 1.
    • getModification

      public String getModification()
      Retrieves the modification string.
      Returns:
      the modification string.
    • accept

      public void accept(VisitorInterface visitor)
      Accepts a visitor object and allows it to visit this instance of ExtendedStatement. This method is part of the Visitor design pattern.
      Specified by:
      accept in class Statement
      Parameters:
      visitor - the visitor object that will visit this instance
    • assemble

      public String assemble() throws InvalidAssemblyFileException
      Assembles the statement into its object code representation.
      Specified by:
      assemble in class Statement
      Returns:
      The assembled object code as a string.
      Throws:
      InvalidAssemblyFileException - If there is an error in the assembly process.