Class SingleValue

java.lang.Object
io.matita08.value.Value
io.matita08.value.SingleValue

public class SingleValue extends Value
Concrete implementation of Value representing a single-word value. This class stores a single integer value with optional sign interpretation, making it suitable for most CPU register and memory operations.

SingleValue supports both signed and unsigned interpretations of the same bit pattern, allowing for flexible arithmetic operations and proper handling of different data types within the CPU simulation.

Since:
1.0
  • Constructor Details

    • SingleValue

      public SingleValue(int n)
      Constructs a new SingleValue with the specified numeric value. The value is treated as unsigned by default.
      Parameters:
      n - the numeric value to store
    • SingleValue

      public SingleValue(int n, boolean sign)
      Constructs a new SingleValue with the specified numeric value and sign interpretation.
      Parameters:
      n - the numeric value to store
      sign - true for signed interpretation, false for unsigned
  • Method Details

    • getSigned

      public int getSigned()
      Gets the value interpreted as a signed integer. The sign interpretation depends on the value type and configuration.

      For SingleValue, returns the stored value with sign interpretation applied. If this value is marked as signed, returns the value as-is. Otherwise, converts from unsigned to signed representation.

      Specified by:
      getSigned in class Value
      Returns:
      the value as a signed integer
    • getUnsigned

      public int getUnsigned()
      Gets the value interpreted as an unsigned integer. All negative representations are treated as positive values.

      For SingleValue, returns the stored value as an unsigned integer. If this value is marked as signed, converts to unsigned representation. Otherwise, returns the value as-is.

      Specified by:
      getUnsigned in class Value
      Returns:
      the value as an unsigned integer
    • set

      public Value set(int n)
      Sets this value to the specified numeric value. The behavior depends on the concrete value type - some types may return a new instance while others modify the current instance.

      For SingleValue, updates the stored value and returns this instance for method chaining.

      Specified by:
      set in class Value
      Parameters:
      n - the new numeric value
      Returns:
      the value instance (may be this instance or a new one)
    • add

      public Value add(Value v2)
      Performs addition with another value. The operation is performed using the appropriate numeric representation and may handle sign extension or overflow based on the value types involved.

      For SingleValue, performs signed addition and returns a new SingleValue containing the result.

      Specified by:
      add in class Value
      Parameters:
      v2 - the value to add to this value
      Returns:
      a new value containing the sum
    • sub

      public Value sub(Value v2)
      Performs subtraction with another value. The operation is performed using the appropriate numeric representation and may handle sign extension or underflow based on the value types involved.

      For SingleValue, performs signed subtraction and returns a new SingleValue containing the result.

      Specified by:
      sub in class Value
      Parameters:
      v2 - the value to subtract from this value
      Returns:
      a new value containing the difference
    • mul

      public Value mul(Value v2)
      Performs multiplication with another value. The operation is performed using the appropriate numeric representation and may handle overflow based on the value types involved.

      For SingleValue, performs signed multiplication and returns a new SingleValue containing the result.

      Specified by:
      mul in class Value
      Parameters:
      v2 - the value to multiply with this value
      Returns:
      a new value containing the product
    • unset

      public static String unset()

      For SingleValue, returns "?" to indicate an uninitialized state.