import numpy as np class Memory: def __init__(self, size): self._memory = np.zeros(size) def write(self, address, data): address = int(address) if 0 > address >= self._memory.size: # TODO: Raise an exception and throw an interrupt here raise RuntimeException('Invalid write address') self._memory[address] = data def read(self, address): address = int(address) if 0 > address >= self._memory.size: # TODO: Raise an exception and throw an interrupt here raise RuntimeException('Invalid write address') return self._memory[address] def clear(self, data=0): self._memory.fill(data) def size(self): return self._memory.size