Simple Machine

Arch.SM213.Machine.Student
Class MainMemory

java.lang.Object
  extended by java.util.Observable
      extended by Util.AbstractDataModel
          extended by Machine.AbstractMainMemory
              extended by Arch.SM213.Machine.Student.MainMemory
All Implemented Interfaces:
DataModel

public class MainMemory
extends AbstractMainMemory

Main Memory of Simple CPU Provides an abstraction of main memory (DRAM).


Nested Class Summary
 
Nested classes/interfaces inherited from class Machine.AbstractMainMemory
AbstractMainMemory.InvalidAddressException
 
Constructor Summary
MainMemory(int byteCapacity)
          Allocate memory.
 
Method Summary
 int bytesToInteger(UnsignedByte byteAtAddrPlus0, UnsignedByte byteAtAddrPlus1, UnsignedByte byteAtAddrPlus2, UnsignedByte byteAtAddrPlus3)
          Convert an sequence of four bytes into a Big Endian integer.
protected  UnsignedByte[] get(int address, int length)
          Fetch a sequence of bytes from memory.
 UnsignedByte[] integerToBytes(int i)
          Convert a Big Endian integer into an array of 4 bytes organized by memory address.
protected  boolean isAccessAligned(int address, int length)
          Determine whether an address is aligned to specified length.
 int length()
          Determine the size of memory.
protected  void set(int address, UnsignedByte[] value)
          Store a sequence of bytes into memory.
 
Methods inherited from class Machine.AbstractMainMemory
getColumnClass, getColumnCount, getColumnName, getRowCount, getValueAt, isCellEditable, read, readInteger, readIntegerUnaligned, readUnaligned, setValueAt, setValueAt, setValueAtByUser, setValueAtByUser, write, writeInteger, writeIntegerUnaligned, writeUnaligned
 
Methods inherited from class Util.AbstractDataModel
addUndoableEditListener, canDeleteRow, canInsertRow, deleteRow, insertRow, tellObservers, tellObservers
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface Util.DataModel
addObserver
 

Constructor Detail

MainMemory

public MainMemory(int byteCapacity)
Allocate memory.

Parameters:
byteCapacity - size of memory in bytes
Method Detail

isAccessAligned

protected boolean isAccessAligned(int address,
                                  int length)
Determine whether an address is aligned to specified length.

Specified by:
isAccessAligned in class AbstractMainMemory
Parameters:
address - memory address
length - byte length
Returns:
true iff address is aligned to length

bytesToInteger

public int bytesToInteger(UnsignedByte byteAtAddrPlus0,
                          UnsignedByte byteAtAddrPlus1,
                          UnsignedByte byteAtAddrPlus2,
                          UnsignedByte byteAtAddrPlus3)
Convert an sequence of four bytes into a Big Endian integer.

Specified by:
bytesToInteger in class AbstractMainMemory
Parameters:
byteAtAddrPlus0 - value of byte with lowest memory address (base address)
byteAtAddrPlus1 - value of byte at base address plus 1
byteAtAddrPlus2 - value of byte at base address plus 2
byteAtAddrPlus3 - value of byte at base address plus 3 (highest memory address)
Returns:
Big Endian integer formed by these four bytes

integerToBytes

public UnsignedByte[] integerToBytes(int i)
Convert a Big Endian integer into an array of 4 bytes organized by memory address.

Specified by:
integerToBytes in class AbstractMainMemory
Parameters:
i - an Big Endian integer
Returns:
an array of UnsignedByte where [0] is value of low-address byte of the number etc.

get

protected UnsignedByte[] get(int address,
                             int length)
                      throws AbstractMainMemory.InvalidAddressException
Fetch a sequence of bytes from memory.

Specified by:
get in class AbstractMainMemory
Parameters:
address - address of the first byte to fetch
length - number of bytes to fetch
Returns:
an array of UnsignedByte where [0] is memory value at address, [1] is memory value at address+1 etc.
Throws:
AbstractMainMemory.InvalidAddressException - if address is out of range.

set

protected void set(int address,
                   UnsignedByte[] value)
            throws AbstractMainMemory.InvalidAddressException
Store a sequence of bytes into memory.

Specified by:
set in class AbstractMainMemory
Parameters:
address - address of the first byte in memory to receive the specified value
value - an array of UnsignedByte values to store in memory at the specified address
Throws:
InvalidAddressException - if any address in the range address to address+value.length-1 is invalid
AbstractMainMemory.InvalidAddressException

length

public int length()
Determine the size of memory.

Specified by:
length in class AbstractMainMemory
Returns:
the number of bytes allocated to this memory.

Simple Machine