示例#1
0
  /**
   * Returns a piece of memory from a given offset and specified size If the offset + size exceed
   * the current memory-size, the remainder will be filled with empty bytes.
   *
   * @param offset byte address in memory
   * @param size the amount of bytes to return
   * @return ByteBuffer containing the chunk of memory data
   */
  public ByteBuffer memoryChunk(int offset, int size) {

    allocateMemory(offset, size);
    byte[] chunk;
    if (memory != null) chunk = Arrays.copyOfRange(memory.array(), offset, offset + size);
    else chunk = new byte[size];
    return ByteBuffer.wrap(chunk);
  }
示例#2
0
  public DataWord memoryLoad(int address) {

    allocateMemory(address, DataWord.ZERO.getData().length);

    DataWord newMem = new DataWord();
    System.arraycopy(memory.array(), address, newMem.getData(), 0, newMem.getData().length);

    return newMem;
  }
示例#3
0
  /**
   * Allocates a piece of memory and stores value at given offset address
   *
   * @param addr is the offset address
   * @param allocSize size of memory needed to write
   * @param value the data to write to memory
   */
  public void memorySave(int addr, int allocSize, byte[] value) {

    allocateMemory(addr, allocSize);
    System.arraycopy(value, 0, memory.array(), addr, value.length);
  }