Class Registers
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
FieldsModifier and TypeFieldDescriptionstatic intModification flags for tracking which components need GUI updates. -
Method Summary
Modifier and TypeMethodDescriptionstatic ValuegetAcc()Gets the current Accumulator register value.static ValuegetBufIn()Gets the current Input Buffer value.static ValueGets the current Output Buffer value.static ValuegetIr()Gets the current Instruction Register value.static ValuegetMAR()Gets the current Memory Address Register value.static ValuegetMC(int pos) Reads a value from Central Memory at the specified integer address.static ValuegetMC(DoubleValue pos) Reads a value from Central Memory using a DoubleValue address.static ValueReads a value from Central Memory at the specified address.static ValuegetMDR()Gets the current Memory Data Register value.static booleanGets the current state of the Overflow flag.static ValueGets the current Address Pointer value.static ValuegetRegB()Gets the current Register B value.static booleangetZero()Gets the current state of the Zero flag.static DoubleValuepc()Gets the Program Counter register.static voidSets the Accumulator register and updates modification flags.static voidSets the Input Buffer and updates modification flags.static voidSets the Output Buffer and updates modification flags.static voidSets the Instruction Register to a new value.static voidSets the Memory Address Register and updates modification flags.static voidWrites a value to Central Memory at the specified integer address.static voidsetMC(DoubleValue pos, Value val) Writes a value to Central Memory using a DoubleValue address.static voidWrites a value to Central Memory using a generic Value address.static voidSets the Memory Data Register and updates modification flags.static voidsetOverflow(boolean overflow) Sets the Overflow flag state.static voidsetPointer(Value pointer) Sets the Address Pointer and updates modification flags.static voidSets Register B and updates modification flags.static voidsetZero(boolean zero) Sets the Zero flag state.
-
Field Details
-
modFlag
public static int modFlagModification 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
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
Gets the current Instruction Register value.Contains the instruction currently being decoded or executed.
- Returns:
- the current IR value
-
setIr
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
Gets the current Address Pointer value.Used for indirect addressing in instructions like LOAD and STORE.
- Returns:
- the current pointer value
-
setPointer
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
Gets the current Memory Address Register value.Contains the address for the current or next memory operation.
- Returns:
- the current MAR value
-
setMAR
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 DoubleValueval- the value to write to memory
-
setMC
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 integerval- the value to write to memory
-
setMC
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 objectval- 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
-