Enum Class Operations4Bit

java.lang.Object
java.lang.Enum<Operations4Bit>
io.matita08.logic.Operations4Bit
All Implemented Interfaces:
Serializable, Comparable<Operations4Bit>, Constable

public enum Operations4Bit extends Enum<Operations4Bit>
4-Bit CPU Instruction Set Implementation. This enum defines a more comprehensive instruction set for a 4-bit CPU architecture, implementing extended operations including subtraction, unconditional jumps, and additional conditional branching capabilities.

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:
  • Enum Constant Details

    • load

      public static final Operations4Bit 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

      public static final Operations4Bit 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

      public static final Operations4Bit 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

      public static final Operations4Bit 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

      public static final Operations4Bit 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

      public static final Operations4Bit 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

      public static final Operations4Bit 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

      public static final Operations4Bit 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

      public static final Operations4Bit 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

      public static final Operations4Bit 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

      public static final Operations4Bit 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

      public static final Operations4Bit 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

      public static final Operations4Bit[] all
      Array containing all available operations in this instruction set.
    • wrapper

      public final Operation wrapper
      The Operation wrapper object that provides the execution interface.
  • Method Details

    • values

      public static Operations4Bit[] 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

      public static Operations4Bit valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • getHalt

      public static Operation 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

      public static Operation 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