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, AbstractMainMemory.MMU, AbstractMainMemory.Port
 
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, getPort, getRowCount, getValueAt, isCellEditable, newInstance, read, readInteger, readIntegerUnaligned, readUnaligned, setValueAt, setValueAt, setValueAtByUser, setValueAtByUser, valueEquals, 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:
InvalidAddressException - if any address in the range address to address+value.length-1 is invalid.
AbstractMainMemory.InvalidAddressException

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 recieve 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

Copyright © 2010, 2011 Mike Feeley. All Rights Reserved.