Enum Class Operations4Bit
- All Implemented Interfaces:
Serializable,Comparable<Operations4Bit>,Constable
Extended Instruction Set:
- LOAD (0) - Load value from memory address to accumulator
- STO (1) - Store accumulator to memory address
- SET (2) - Copy accumulator value to RegB
- IN (3) - Input value from input buffer to accumulator
- OUT (4) - Output accumulator value to output buffer
- ADD (5) - Add RegB to accumulator
- SUB (6) - Subtract RegB from accumulator
- JMP (7) - Unconditional jump to address
- JPZ (8) - Jump to address if zero flag is set
- JPO (9) - Jump to address if overflow flag is set
- HALT (15) - Stop CPU execution
This instruction set provides enhanced control flow capabilities compared to the 3-bit version, including unconditional jumps and overflow-based conditional branching.
Note: This is an alternative instruction set that can be selected via command-line arguments. Many operations are currently implemented as stubs and require completion for full functionality.
- Since:
- 1.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionADD (Addition) - Opcode 5.HALT (Halt Execution) - Opcode 15.IN (Input) - Opcode 3.JMP (Unconditional Jump) - Opcode 7.JPO (Jump if Overflow) - Opcode 9.JPZ (Jump if Zero) - Opcode 8.LOAD (Load) - Opcode 0.OUT (Output) - Opcode 4.SET (Set Register B) - Opcode 2.STO (Store) - Opcode 1.SUB (Subtraction) - Opcode 6.UNKNOWN (Invalid Opcode Handler) - Opcode 16. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Operations4Bit[]Array containing all available operations in this instruction set.final OperationThe Operation wrapper object that provides the execution interface. -
Method Summary
Modifier and TypeMethodDescriptionstatic OperationgetHalt()Gets the HALT operation for CPU termination.static OperationGets the UNKNOWN operation for invalid opcodes.static Operations4BitReturns the enum constant of this class with the specified name.static Operations4Bit[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
load
LOAD (Load) - Opcode 0. Loads a value from the memory address specified by the pointer register into the accumulator. This is a multi-cycle operation.Status: Stub implementation - requires completion
Execution cycles: 2
-
sto
STO (Store) - Opcode 1. Stores the current accumulator value to the memory address specified by the pointer register. This is a multi-cycle operation.Status: Stub implementation - requires completion
Execution cycles: 2
-
set
SET (Set Register B) - Opcode 2. Copies the current accumulator value to RegB. This is typically used to prepare operands for arithmetic operations.Execution cycles: 1 (single-cycle operation)
-
in
IN (Input) - Opcode 3. Copies the current input buffer value to the accumulator register. This provides the interface between input devices and the CPU.Status: Stub implementation - requires completion
Execution cycles: 1 (single-cycle operation)
-
out
OUT (Output) - Opcode 4. Copies the current accumulator value to the output buffer register. This provides the interface between the CPU and output devices.Status: Stub implementation - requires completion
Execution cycles: 1 (single-cycle operation)
-
add
ADD (Addition) - Opcode 5. Performs arithmetic addition of the accumulator and RegB, storing the result in the accumulator. Should update CPU flags.Status: Stub implementation - requires completion
Execution cycles: 1 (single-cycle operation)
-
sub
SUB (Subtraction) - Opcode 6. Performs arithmetic subtraction of RegB from the accumulator, storing the result in the accumulator. Should update CPU flags.Status: Stub implementation - requires completion
Execution cycles: 1 (single-cycle operation)
-
jmp
JMP (Unconditional Jump) - Opcode 7. Unconditionally jumps to the address specified by the pointer register. This is a multi-cycle operation that reads the target address then jumps.Execution logic:
- Cycle 2: Read target address from memory into pointer
- Cycle 1: Set PC to pointer value
Execution cycles: 2
-
jpz
JPZ (Jump if Zero) - Opcode 8. Conditional jump instruction that jumps to the specified address if the Zero flag is set. If the flag is not set, execution continues with the next instruction.Status: Stub implementation - requires completion
Execution cycles: 1
-
jpo
JPO (Jump if Overflow) - Opcode 9. Conditional jump instruction that jumps to the specified address if the Overflow flag is set. If the flag is not set, execution continues with the next instruction.Status: Stub implementation - requires completion
Execution cycles: 1
-
Halt
HALT (Halt Execution) - Opcode 15. Stops CPU execution. This instruction causes the CPU to enter a halted state where no further instructions are processed.Execution cycles: 1 (single-cycle operation)
-
Unknown
UNKNOWN (Invalid Opcode Handler) - Opcode 16. Special operation used as a fallback for invalid or unrecognized opcodes. Provides graceful handling of instruction decode errors.
-
-
Field Details
-
all
Array containing all available operations in this instruction set. -
wrapper
The Operation wrapper object that provides the execution interface.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getHalt
Gets the HALT operation for CPU termination. Used by the Operation class during dynamic loading to identify the halt instruction.- Returns:
- the HALT operation wrapper
-
getUnknown
Gets the UNKNOWN operation for invalid opcodes. Used by the Operation class during dynamic loading to handle unrecognized instruction codes.- Returns:
- the UNKNOWN operation wrapper
-