Class ControlUnit
This class maintains the state of the CPU's control unit, tracking execution phases, instruction cycles, and current operations. It serves as the central coordinator for instruction execution flow.
State Components:
- Execution Phases: Current and next phases (Fetch/Decode/Execute)
- Cycle Management: Current cycle within instruction execution
- Operation Tracking: Current instruction being executed
- ALU Status: Current arithmetic/logic operation display
The control unit coordinates with the execution engine to manage the fetch-decode-execute cycle and handle multi-cycle instruction execution.
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic StringString representation of current ALU operation for display.static PhaseCurrent execution phase of the CPU.static intCurrent cycle number within the current instruction execution.static PhaseNext execution phase to transition to.static OperationCurrent operation being executed.static intTotal number of cycles required for the current instruction. -
Method Summary
-
Field Details
-
current
Current execution phase of the CPU.Represents the current state in the instruction cycle: Fetch, Decode, Execute, or None (inactive).
-
next
Next execution phase to transition to.Set by the current phase to determine the next phase in the instruction execution cycle.
-
currentCycle
public static int currentCycleCurrent cycle number within the current instruction execution.Counts down from the total cycles required for the current instruction. When it reaches 0, the instruction execution is complete.
-
totalCycles
public static int totalCyclesTotal number of cycles required for the current instruction.Set during the decode phase based on the instruction being executed. Used for progress tracking and multi-cycle instruction coordination.
-
opcode
Current operation being executed.Set during decode phase and used throughout execution. Contains the instruction's execution logic and metadata.
-
ALUOpcode
String representation of current ALU operation for display.Used by the GUI to show which arithmetic/logic operation is currently being performed. Set by arithmetic instructions.
-