computer
Class Memory

java.lang.Object
  extended by computer.Memory

public class Memory
extends java.lang.Object

A dense array-like structure representing the memory of a toy computer. The memory may hold cells of type Code, either Data cells or Instruction cells.

Author:
jbergin

Field Summary
private  apcsGeneric.jbergin.DenseList<Code> storage
           
 
Constructor Summary
Memory()
          Create a memory of size 1K or 1024 cells.
 
Method Summary
 Instruction getInstruction(int cell)
          Retrieve an instruction cell from the memory.
 Data getValue(int cell)
          Retrieve a data cell from the memory.
 void put(Code code, int cell)
          Insert a cell into the memory at a fixed address
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

storage

private apcsGeneric.jbergin.DenseList<Code> storage
Constructor Detail

Memory

public Memory()
Create a memory of size 1K or 1024 cells.

Method Detail

put

public void put(Code code,
                int cell)
Insert a cell into the memory at a fixed address

Parameters:
code - the cell to be inserted. It may be Data or Instruction
cell - the address at which to put the item in range: 0..1023

getValue

public Data getValue(int cell)
Retrieve a data cell from the memory. An error will occur if it isn't a data cell

Parameters:
cell - the address of the desired cell
Returns:
the cell at the required address
Throws:
java.lang.ClassCastException - if the cell has the wrong type

getInstruction

public Instruction getInstruction(int cell)
Retrieve an instruction cell from the memory. An error will occur if it isn't an instruction cell

Parameters:
cell - the address of the desired cell
Returns:
the cell at the required address
Throws:
java.lang.ClassCastException - if the cell has the wrong type