Package io.matita08.logic
Class Operation
java.lang.Object
io.matita08.logic.Operation
Represents a CPU operation/instruction in the simulator with dynamic loading capabilities.
This class serves as a wrapper for CPU operations that can be executed by the simulation engine.
The Operation class uses reflection to dynamically load operation definitions from
an external enum class specified by Constants.getOperationEnumName(). This design
allows for flexible operation sets without modifying the core simulation logic.
Each operation contains:
- Opcode: Numeric identifier for the operation
- Action: Consumer function that implements the operation logic
- Cycles: Number of CPU cycles required for execution
- Name: Human-readable operation name
The class maintains static references to special operations like Halt and
Unknown, and provides utility methods for operation lookup and CPU interaction.
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe executable action for this operation.static Operation[]Array containing all available operations loaded from the external enum.final intThe number of CPU cycles required to execute this operation.static OperationSpecial operation representing a halt/stop instruction.final StringThe human-readable name of this operation.final intThe numeric opcode identifier for this operation.static OperationDefault operation used when an invalid opcode is encountered. -
Method Summary
Modifier and TypeMethodDescriptionstatic Operationget(int opcode) Retrieves an operation by its opcode identifier.static intGets the address size used by the CPU architecture.static ValueGets the current Program Counter value and increments it for the next instruction.static voidInitiates a memory read operation from the specified address.static voidreadPointer(int cycle) Initiates a pointer read operation for the specified cycle.static voidSets a value in central memory at the specified address.static voidsetRemainingCycles(int remaining) Sets the number of remaining execution cycles for the current operation.
-
Field Details
-
Halt
Special operation representing a halt/stop instruction. This operation typically terminates program execution. -
Unknown
Default operation used when an invalid opcode is encountered. This operation handles error cases gracefully. -
all
Array containing all available operations loaded from the external enum. Operations are indexed by their position in the source enum. -
action
The executable action for this operation. Takes an integer parameter (typically an operand) and performs the operation. -
opcode
public final int opcodeThe numeric opcode identifier for this operation. Used to match instructions to their corresponding operations. -
cycles
public final int cyclesThe number of CPU cycles required to execute this operation. Used for accurate timing simulation. -
name
The human-readable name of this operation. Used for debugging and display purposes.
-
-
Method Details
-
get
Retrieves an operation by its opcode identifier. If no matching operation is found, returns theUnknownoperation and prints diagnostic information about available operations.- Parameters:
opcode- the opcode to search for- Returns:
- the matching Operation, or
Unknownif not found
-
setRemainingCycles
public static void setRemainingCycles(int remaining) Sets the number of remaining execution cycles for the current operation. When cycles reach 1, automatically sets the next phase to Fetch for the next instruction.- Parameters:
remaining- the number of cycles remaining for the current operation
-
getAddressSize
public static int getAddressSize()Gets the address size used by the CPU architecture. This is a convenience method that delegates toConstants.getAddressSize().- Returns:
- the address size in bytes/words
-
readPointer
public static void readPointer(int cycle) Initiates a pointer read operation for the specified cycle. This method delegates to the execution engine to handle pointer dereferencing.- Parameters:
cycle- the execution cycle when the read should occur
-
setMC
Sets a value in central memory at the specified address. This method updates both the MAR (Memory Address Register) and MDR (Memory Data Register) before writing to central memory.- Parameters:
address- the memory address where the value should be storedvalue- the value to store in memory
-
readMC
Initiates a memory read operation from the specified address. This method sets up the Memory Address Register for reading and delegates to the execution engine.- Parameters:
address- the memory address to read from
-
getAndIncPc
Gets the current Program Counter value and increments it for the next instruction. This method is commonly used during instruction fetching to advance program execution.- Returns:
- the current PC value before incrementing
-