Class Registers

java.lang.Object
io.matita08.data.Registers

public final class Registers extends Object
CPU Register and Memory Management System.

This class manages all CPU registers, Central Memory, and provides centralized access to CPU state. It handles modification tracking for efficient GUI updates and integrates with the flag system for arithmetic operations.

Managed Components:

  • Core Registers: PC, IR, MAR, MDR, Accumulator, RegB
  • Memory: Central Memory (MC) with configurable size
  • I/O: Input and Output buffer registers
  • Addressing: Pointer register for indirect addressing
  • Flags: Interface to CPU flags (Zero, Overflow)

Modification Tracking: The modFlag field uses bit flags to track which components have been modified since the last GUI update:

  • Bit 0: Central Memory modified
  • Bit 1: MAR/MDR/Pointer modified
  • Bit 2: Accumulator/RegB modified
  • Bit 3: I/O buffers modified

Since:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static int
    Modification flags for tracking which components need GUI updates.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Value
    Gets the current Accumulator register value.
    static Value
    Gets the current Input Buffer value.
    static Value
    Gets the current Output Buffer value.
    static Value
    Gets the current Instruction Register value.
    static Value
    Gets the current Memory Address Register value.
    static Value
    getMC(int pos)
    Reads a value from Central Memory at the specified integer address.
    static Value
    Reads a value from Central Memory using a DoubleValue address.
    static Value
    getMC(Value pos)
    Reads a value from Central Memory at the specified address.
    static Value
    Gets the current Memory Data Register value.
    static boolean
    Gets the current state of the Overflow flag.
    static Value
    Gets the current Address Pointer value.
    static Value
    Gets the current Register B value.
    static boolean
    Gets the current state of the Zero flag.
    pc()
    Gets the Program Counter register.
    static void
    Sets the Accumulator register and updates modification flags.
    static void
    setBufIn(Value bufIn)
    Sets the Input Buffer and updates modification flags.
    static void
    setBufOut(Value bufOut)
    Sets the Output Buffer and updates modification flags.
    static void
    Sets the Instruction Register to a new value.
    static void
    Sets the Memory Address Register and updates modification flags.
    static void
    setMC(int index, Value val)
    Writes a value to Central Memory at the specified integer address.
    static void
    setMC(DoubleValue pos, Value val)
    Writes a value to Central Memory using a DoubleValue address.
    static void
    setMC(Value pos, Value val)
    Writes a value to Central Memory using a generic Value address.
    static void
    Sets the Memory Data Register and updates modification flags.
    static void
    setOverflow(boolean overflow)
    Sets the Overflow flag state.
    static void
    setPointer(Value pointer)
    Sets the Address Pointer and updates modification flags.
    static void
    setRegB(Value regB)
    Sets Register B and updates modification flags.
    static void
    setZero(boolean zero)
    Sets the Zero flag state.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • modFlag

      public static int modFlag
      Modification flags for tracking which components need GUI updates.

      Bit field structure:

      • Bit 0 (0x01): Central Memory modified
      • Bit 1 (0x02): MAR/MDR/Pointer modified
      • Bit 2 (0x04): Accumulator/RegB modified
      • Bit 3 (0x08): I/O buffers modified

  • Method Details

    • pc

      public static DoubleValue pc()
      Gets the Program Counter register.

      The PC automatically advances during instruction fetch and can be modified by jump instructions for flow control.

      Returns:
      the PC register as a DoubleValue
    • getIr

      public static Value getIr()
      Gets the current Instruction Register value.

      Contains the instruction currently being decoded or executed.

      Returns:
      the current IR value
    • setIr

      public static void setIr(Value ir)
      Sets the Instruction Register to a new value.

      Typically called during the instruction fetch phase when loading the next instruction from memory.

      Parameters:
      ir - the new instruction value to store in IR
    • getPointer

      public static Value getPointer()
      Gets the current Address Pointer value.

      Used for indirect addressing in instructions like LOAD and STORE.

      Returns:
      the current pointer value
    • setPointer

      public static void setPointer(Value pointer)
      Sets the Address Pointer and updates modification flags.

      Updates the pointer register and marks address registers as modified for GUI update coordination.

      Parameters:
      pointer - the new pointer address value
    • getMAR

      public static Value getMAR()
      Gets the current Memory Address Register value.

      Contains the address for the current or next memory operation.

      Returns:
      the current MAR value
    • setMAR

      public static void setMAR(Value mar)
      Sets the Memory Address Register and updates modification flags.

      Sets the target address for memory read/write operations and triggers GUI update flags.

      Parameters:
      mar - the memory address to set
    • getMDR

      public static Value getMDR()
      Gets the current Memory Data Register value.

      Contains data that was read from or will be written to memory.

      Returns:
      the current MDR value
    • setMDR

      public static void setMDR(Value mdr)
      Sets the Memory Data Register and updates modification flags.

      Sets the data value for memory operations and triggers GUI updates.

      Parameters:
      mdr - the data value to set
    • getAcc

      public static Value getAcc()
      Gets the current Accumulator register value.

      The accumulator is the primary register for arithmetic and logic operations, serving as both operand and result storage.

      Returns:
      the current Accumulator value
    • setAcc

      public static void setAcc(Value acc)
      Sets the Accumulator register and updates modification flags.

      Updates the accumulator value and marks arithmetic registers as modified for GUI updates.

      Parameters:
      acc - the new Accumulator value
    • getRegB

      public static Value getRegB()
      Gets the current Register B value.

      Register B serves as the secondary operand for arithmetic operations and general-purpose temporary storage.

      Returns:
      the current Register B value
    • setRegB

      public static void setRegB(Value regB)
      Sets Register B and updates modification flags.

      Updates RegB and triggers GUI update flags for arithmetic registers.

      Parameters:
      regB - the new Register B value
    • getBufIn

      public static Value getBufIn()
      Gets the current Input Buffer value.

      The input buffer receives data from external input devices and makes it available to the CPU via the IN instruction.

      Returns:
      the current input buffer value
    • setBufIn

      public static void setBufIn(Value bufIn)
      Sets the Input Buffer and updates modification flags.

      Updates the input buffer (typically from external devices) and marks I/O buffers as modified.

      Parameters:
      bufIn - the new input buffer value
    • getBufOut

      public static Value getBufOut()
      Gets the current Output Buffer value.

      The output buffer holds data sent from the CPU to external output devices via the OUT instruction.

      Returns:
      the current output buffer value
    • setBufOut

      public static void setBufOut(Value bufOut)
      Sets the Output Buffer and updates modification flags.

      Updates the output buffer (typically for external devices) and marks I/O buffers as modified.

      Parameters:
      bufOut - the new output buffer value
    • getMC

      public static Value getMC(Value pos)
      Reads a value from Central Memory at the specified address.

      Supports both single values and double values as addresses. Returns null value if the address is invalid or out of bounds.

      Parameters:
      pos - the memory address as a Value object
      Returns:
      the value stored at that address, or null value if invalid
    • getMC

      public static Value getMC(DoubleValue pos)
      Reads a value from Central Memory using a DoubleValue address.

      Converts the DoubleValue address to an integer and retrieves the corresponding memory contents.

      Parameters:
      pos - the memory address as a DoubleValue
      Returns:
      the value stored at that address
    • getMC

      public static Value getMC(int pos)
      Reads a value from Central Memory at the specified integer address.

      Provides bounds checking and dynamic memory expansion if necessary. Returns null value for out-of-bounds addresses.

      Parameters:
      pos - the memory address as an integer
      Returns:
      the value stored at that address, or null value if out of bounds
    • setMC

      public static void setMC(DoubleValue pos, Value val)
      Writes a value to Central Memory using a DoubleValue address.

      Updates both the memory contents and the modification flags for GUI coordination.

      Parameters:
      pos - the memory address as a DoubleValue
      val - the value to write to memory
    • setMC

      public static void setMC(int index, Value val)
      Writes a value to Central Memory at the specified integer address.

      Performs bounds checking and updates modification flags. Silently ignores writes to out-of-bounds addresses.

      Parameters:
      index - the memory address as an integer
      val - the value to write to memory
    • setMC

      public static void setMC(Value pos, Value val)
      Writes a value to Central Memory using a generic Value address.

      Handles type checking and delegates to the appropriate overloaded method.

      Parameters:
      pos - the memory address as a Value object
      val - the value to write to memory
    • getZero

      public static boolean getZero()
      Gets the current state of the Zero flag.

      The Zero flag is set when arithmetic operations result in zero. Used by conditional jump instructions like JPZ.

      Returns:
      true if the Zero flag is set, false otherwise
    • setZero

      public static void setZero(boolean zero)
      Sets the Zero flag state.

      Typically called by arithmetic instructions to indicate whether their result was zero.

      Parameters:
      zero - the new state of the Zero flag
    • getOverflow

      public static boolean getOverflow()
      Gets the current state of the Overflow flag.

      The Overflow flag is set when arithmetic operations exceed the maximum representable value.

      Returns:
      true if the Overflow flag is set, false otherwise
    • setOverflow

      public static void setOverflow(boolean overflow)
      Sets the Overflow flag state.

      Typically called by arithmetic instructions to indicate whether their result caused an overflow condition.

      Parameters:
      overflow - the new state of the Overflow flag