1 package net.mograsim.machine.standard.memory;
3 import java.math.BigInteger;
5 import net.mograsim.logic.core.types.Bit;
6 import net.mograsim.logic.core.types.BitVector;
7 import net.mograsim.machine.GenericMemory;
8 import net.mograsim.machine.MainMemory;
9 import net.mograsim.machine.MainMemoryDefinition;
11 public class WordAddressableMemory extends GenericMemory<BitVector> implements MainMemory
13 private final int cellWidth;
14 private final MainMemoryDefinition definition;
16 public WordAddressableMemory(MainMemoryDefinition definition)
19 this.cellWidth = definition.getCellWidth();
20 this.definition = definition;
24 public void setCell(long address, BitVector data)
27 super.setCell(address, data);
31 public BitVector getCell(long address)
33 BitVector data = super.getCell(address);
34 return data == null ? BitVector.of(Bit.ZERO, cellWidth) : data;
38 public BigInteger getCellAsBigInteger(long address)
40 BitVector data = getCell(address);
41 return data == null ? BigInteger.valueOf(0) : data.getUnsignedValue();
45 public void setCellAsBigInteger(long address, BigInteger data)
47 setCell(address, BitVector.from(data, cellWidth));
51 public MainMemoryDefinition getDefinition()