Class RegisterStatement


public class RegisterStatement extends BaseStatement
The RegisterStatement class represents a statement that involves register operations in an assembler. It extends the BaseStatement class and includes two registers (reg1 and reg2). The format of the statement is set to 2, and the size is adjusted accordingly.
  • Constructor Details

    • RegisterStatement

      public RegisterStatement()
      Constructs a new RegisterStatement with default values. Initializes the format to 2, sets the size based on the format, and initializes both reg1 and reg2 to new HexNum instances with a value of 0.
    • RegisterStatement

      public RegisterStatement(HexNum location, HexNum opcode, HexNum reg1)
      Constructs a RegisterStatement with the specified location, opcode, and register 1.
      Parameters:
      location - the memory location of the statement
      opcode - the operation code of the statement
      reg1 - the first register involved in the statement
    • RegisterStatement

      public RegisterStatement(HexNum location, HexNum opcode, HexNum reg1, HexNum reg2)
      Constructs a RegisterStatement with the specified location, opcode, and registers.
      Parameters:
      location - the memory location of the statement
      opcode - the operation code of the statement
      reg1 - the first register involved in the statement
      reg2 - the second register involved in the statement
  • Method Details

    • setReg1

      public void setReg1(HexNum reg1)
      Sets the value of the first register.
      Parameters:
      reg1 - the HexNum object to set as the first register. If reg1 is null, the current value of reg1 will not be changed.
    • setReg2

      public void setReg2(HexNum reg2)
      Sets the value of the second register.
      Parameters:
      reg2 - the HexNum object to set as the second register. If reg2 is null, the current value of reg2 will not be changed.
    • setOpcode

      public void setOpcode(HexNum opcode)
      Sets the opcode for this RegisterStatement.
      Parameters:
      opcode - the HexNum object representing the opcode to be set
    • assemble

      public String assemble()
      Assembles the opcode and register values into a hex string representation.
      Specified by:
      assemble in class Statement
      Returns:
      A hex string representation of the opcode and register values.
    • accept

      public void accept(VisitorInterface visitor)
      Accepts a visitor object and allows it to visit this RegisterStatement instance.
      Specified by:
      accept in class Statement
      Parameters:
      visitor - the visitor object that will visit this instance