Package edu.iu.jrsalata
Class RegisterStatement
java.lang.Object
edu.iu.jrsalata.Statement
edu.iu.jrsalata.BaseStatement
edu.iu.jrsalata.RegisterStatement
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.
-
Field Summary
Fields 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 a new RegisterStatement with default values.RegisterStatement
(HexNum location, HexNum opcode, HexNum reg1) Constructs a RegisterStatement with the specified location, opcode, and register 1.RegisterStatement
(HexNum location, HexNum opcode, HexNum reg1, HexNum reg2) Constructs a RegisterStatement with the specified location, opcode, and registers. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(VisitorInterface visitor) Accepts a visitor object and allows it to visit this RegisterStatement instance.assemble()
Assembles the opcode and register values into a hex string representation.void
Sets the opcode for this RegisterStatement.void
Sets the value of the first register.void
Sets the value of the second register.Methods inherited from class edu.iu.jrsalata.BaseStatement
getLocation, setLocation
Methods inherited from class edu.iu.jrsalata.Statement
getBlock, getControlSection, getLine, getSize, setBlock, setControlSection, setLine
-
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
Constructs a RegisterStatement with the specified location, opcode, and register 1.- Parameters:
location
- the memory location of the statementopcode
- the operation code of the statementreg1
- the first register involved in the statement
-
RegisterStatement
Constructs a RegisterStatement with the specified location, opcode, and registers.- Parameters:
location
- the memory location of the statementopcode
- the operation code of the statementreg1
- the first register involved in the statementreg2
- the second register involved in the statement
-
-
Method Details
-
setReg1
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
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
Sets the opcode for this RegisterStatement.- Parameters:
opcode
- the HexNum object representing the opcode to be set
-
assemble
Assembles the opcode and register values into a hex string representation. -
accept
Accepts a visitor object and allows it to visit this RegisterStatement instance.
-