Enum Class Operations3Bit

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

public enum Operations3Bit extends Enum<Operations3Bit>
3-Bit CPU Instruction Set Implementation.

This enum defines a complete instruction set for a 3-bit CPU architecture, implementing common operations such as memory access, arithmetic, I/O, and control flow instructions.

Instruction Set:

  • STO (0) - Store accumulator to memory address
  • LOAD (1) - Load value from memory address to accumulator
  • OUT (2) - Output accumulator value to output buffer
  • IN (3) - Input value from input buffer to accumulator
  • ADD (4) - Add RegB to accumulator with flag updates
  • SET (5) - Copy accumulator value to RegB
  • JPZ (6) - Jump to address if zero flag is set
  • HALT (7) - Stop CPU execution

Each instruction is implemented with multi-cycle execution support, handling address reading and memory operations across multiple CPU cycles.

Since:
1.0
  • Enum Constant Details

    • sto

      public static final Operations3Bit sto
      STO (Store) - Opcode 0.

      Stores the current accumulator value to the memory address specified by the pointer register. This is a multi-cycle operation that first reads the target address, then performs the memory write.

      Execution cycles: 1 + address size (typically 3 cycles total)

      • Cycles 2-N: Read pointer address from memory
      • Cycle 1: Store accumulator to memory[pointer]
    • load

      public static final Operations3Bit load
      LOAD (Load) - Opcode 1.

      Loads a value from the memory address specified by the pointer register into the accumulator. This is a multi-cycle operation that first reads the target address, then performs the memory read.

      Execution cycles: 1 + address size (typically 3 cycles total)

      • Cycles 2-N: Read pointer address from memory
      • Cycle 1: Load memory[pointer] into accumulator
    • out

      public static final Operations3Bit out
      OUT (Output) - Opcode 2.

      Copies the current accumulator value to the output buffer register. This provides the interface between the CPU and output devices.

      Execution cycles: 1 (single-cycle operation)

    • in

      public static final Operations3Bit 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.

      Execution cycles: 1 (single-cycle operation)

    • add

      public static final Operations3Bit add
      ADD (Addition) - Opcode 4.

      Performs arithmetic addition of the accumulator and RegB, storing the result in the accumulator. Updates the Zero and Overflow flags based on the result.

      Flag Updates:

      • Overflow flag: Set if result exceeds maximum value
      • Zero flag: Set if result equals zero

      Execution cycles: 1 (single-cycle operation)

    • set

      public static final Operations3Bit set
      SET (Set Register B) - Opcode 5.

      Copies the current accumulator value to RegB. This is typically used to prepare operands for arithmetic operations.

      Execution cycles: 1 (single-cycle operation)

    • jpz

      public static final Operations3Bit jpz
      JPZ (Jump if Zero) - Opcode 6.

      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.

      Execution cycles: 1 + address size (typically 3 cycles total)

      • Cycles N-2: Read target address from memory
      • Cycle 1: Check Zero flag and jump if set, otherwise continue
    • Halt

      public static final Operations3Bit Halt
      HALT (Halt Execution) - Opcode 7.

      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 Operations3Bit Unknown
      UNKNOWN (Invalid Opcode Handler).

      Special operation used as a fallback for invalid or unrecognized opcodes. Provides graceful handling of instruction decode errors.

  • Field Details

    • all

      public static final Operations3Bit[] 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 Operations3Bit[] 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 Operations3Bit 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
    • get

      public Operation get()
      Gets the Operation wrapper for this instruction.
      Returns:
      the Operation object containing execution logic and metadata
    • getHalt

      public static Operation getHalt()
      Gets the HALT operation for CPU termination.
      Returns:
      the HALT operation wrapper
    • getUnknown

      public static Operation getUnknown()
      Gets the UNKNOWN operation for invalid opcodes.
      Returns:
      the UNKNOWN operation wrapper