/// <summary> /// Constructs a memory stick, with the specified size /// </summary> /// <param name="size">The size of the memory</param> public Memory(int size) { Registers = new Register[size]; foreach (var i in Enumerable.Range(0, size)) { Registers[i] = new Register(RegisterAddress.FromInt(i), DEFAULT_REGISTER_VALUE); } }
/// <summary> /// Gets the return value of the program - The return value is always the last memory cell. /// </summary> /// <returns>The return value of the program</returns> public BigInteger GetReturnValue() { return(Machine.Memory.Read(RegisterAddress.FromInt(Machine.Memory.Size - 1))); }
/// <summary> /// Reads a value from the specifies Location. /// </summary> /// <param name="address">The address to read from</param> /// <returns>The value at the address.</returns> public uint Read(RegisterAddress address) { return(Registers[address.GetIndex()].Value); }
/// <summary> /// Writes the specifies value to the specified location in memory. /// </summary> /// <param name="address">The address to write to</param> /// <param name="value">The Value to write</param> public void Write(RegisterAddress address, uint value) { Registers[address.GetIndex()].Value = value; }