fi.hu.cs.titokone
Class RandomAccessMemory

java.lang.Object
  extended byfi.hu.cs.titokone.RandomAccessMemory
All Implemented Interfaces:
TTK91Memory

public class RandomAccessMemory
extends java.lang.Object
implements TTK91Memory

This class represents the memory of a TTK-91 computer.


Field Summary
private  int codeAreaSize
           
private  int dataAreaSize
           
private  MemoryLine[] memory
           
private  int size
           
private  SymbolTable symbols
           
 
Constructor Summary
RandomAccessMemory(int size)
          Creates a memory with a given size and initializes it with rows containing 0.
 
Method Summary
 int[] getCodeArea()
          Returns a code area dump.
 int getCodeAreaSize()
          Returns the size of the code area.
 int[] getDataArea()
          Returns a data area dump.
 int getDataAreaSize()
          Returns the size of the data area.
 int[] getMemory()
          Returns a memory dump.
 MemoryLine getMemoryLine(int index)
          Returns memory line at given slot.
 MemoryLine[] getMemoryLines()
          This method returns a copy of all the memory lines.
 int getSize()
          Returns the size of the memory.
 java.util.HashMap getSymbolTable()
          Returns the symbol table of currently used symbols as a hashmap, with String names of the symbols as keys referencing the Integer values of the symbols.
 int getValue(int memorySlot)
          Returns the value of an indexed memory slot.
 void setCodeAreaLength(int size)
          Sets the size of the code area.
 void setDataAreaLength(int size)
          Sets the size of the data area.
 void setMemoryLine(int index, MemoryLine memoryLine)
          Sets new memory line to given memory slot.
 void setSymbolTable(SymbolTable symbols)
          Changes the symbol table stored in this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

symbols

private SymbolTable symbols

size

private int size

memory

private MemoryLine[] memory

codeAreaSize

private int codeAreaSize

dataAreaSize

private int dataAreaSize
Constructor Detail

RandomAccessMemory

public RandomAccessMemory(int size)
Creates a memory with a given size and initializes it with rows containing 0.

Parameters:
size - Size of the memory.
Method Detail

getSize

public int getSize()
Returns the size of the memory. Defined in TTK91Memory.

Specified by:
getSize in interface TTK91Memory
Returns:
Size of the memory.

getValue

public int getValue(int memorySlot)
Returns the value of an indexed memory slot.

Specified by:
getValue in interface TTK91Memory
Parameters:
memorySlot - memory address where required data is
Returns:
Value of an indexed memory slot.

getSymbolTable

public java.util.HashMap getSymbolTable()
Returns the symbol table of currently used symbols as a hashmap, with String names of the symbols as keys referencing the Integer values of the symbols. Defined in TTK91Memory.

Specified by:
getSymbolTable in interface TTK91Memory
Returns:
The symboltable as a hashmap.

getMemory

public int[] getMemory()
Returns a memory dump. Defined in TTK91Memory.

Specified by:
getMemory in interface TTK91Memory
Returns:
Memory dump in integer form.

getCodeArea

public int[] getCodeArea()
Returns a code area dump. Defined in TTK91Memory.

Specified by:
getCodeArea in interface TTK91Memory
Returns:
Code area dump in integer form.

getDataArea

public int[] getDataArea()
Returns a data area dump.

Specified by:
getDataArea in interface TTK91Memory
Returns:
Data area dump in integer form.

getCodeAreaSize

public int getCodeAreaSize()
Returns the size of the code area.

Returns:
Size of the code area.

getDataAreaSize

public int getDataAreaSize()
Returns the size of the data area.

Returns:
Size of the data area.

getMemoryLine

public MemoryLine getMemoryLine(int index)
Returns memory line at given slot.

Parameters:
index - Index to memory.
Returns:
Memory line at given slot.

getMemoryLines

public MemoryLine[] getMemoryLines()
This method returns a copy of all the memory lines.

Returns:
An array containing all the memory lines.

setSymbolTable

public void setSymbolTable(SymbolTable symbols)
Changes the symbol table stored in this class. It is not used by RandomAccessMemory, but can be returned as a HashMap.

Parameters:
symbols - The new symboltable to store here.

setMemoryLine

public void setMemoryLine(int index,
                          MemoryLine memoryLine)
                   throws TTK91AddressOutOfBounds
Sets new memory line to given memory slot.

Parameters:
index - Index to memory.
memoryLine - New memory line which will replace the old.
Throws:
TTK91AddressOutOfBounds

setCodeAreaLength

public void setCodeAreaLength(int size)
Sets the size of the code area.

Parameters:
size - Size of the code area.

setDataAreaLength

public void setDataAreaLength(int size)
Sets the size of the data area.

Parameters:
size - Size of the data area.