The memory unit can be specified at various levels of abstraction. A
hardware engineer might describe the implementation using decoders and
registers. For our purposes, we maintain a high-level behavioral view of
the memory unit as a collection of cells, which we can access in two
different ways, either using a fetch
operation that returns
the contents of a cell, or a store
operation that updates
the contents of a cell.
In Java, the information about the memory can be neatly encapsulated in a
class definition with two public methods, fetch
and
store
. The collection of cells should be maintained
internally and never revealed to memory clients. Clients are, however,
allowed to know the number of memory cells, and are notified whenever a
fetch
or store
attempts to access a non-existing
cell.
We can formally state the requirement implicit in the above paragraph by providing an interface that the memory unit must implement:
public interface MemoryI { int DEFAULT_SIZE = 100; int getSize(); Word fetch (Word a) throws MemoryE; void store (Word a, Word v) throws MemoryE; }
The definition of the interface refers to an exception
MemoryE
that notifies clients of the memory whenever
something goes wrong. The clients can catch the exception and then resume
in any way they deem appropriate. The exception is defined in a class of
its own:
public class MemoryE extends MachineE { public MemoryE (String message) { super(message); } public MemoryE (int address) { super("Address " + address + " is out of range"); } }
Since many errors may occur in the machine, we also define a class
MachineE
and specify that a MemoryE
is-a
MachineE
. There are two ways to create an object
representing a memory exception: either by supplying a string argument
explaining the cause of the error, or by supplying an offending
out-of-range address.
Machine exceptions are also defined in a class of their own:
public class MachineE extends Exception { public MachineE () {} public MachineE (String s) { super(s); } }
The name Exception
is a built-in Java class. Any
Exception
object can be thrown to signal an exceptional
situation, and can be later caught and examined.
We are still working in the package duckMachine.architecture
.
Your job is to implement the class Memory
according to the
following guidelines:
Word
objects
Data
object holding the integer 0
For this assignment, the help files supplied to you at URL
http://www.cs.uoregon.edu/~sabry/duckMachine/memoryUnit/
are:
MemoryI.java
, which contains the interface of the memory
unit
MemoryE.java
and MachineE.java
, which define
the
exceptions raised for illegal memory accesses
Word.java
,Address.java
, and
Data.java
, which represent machine words, addresses and data
respectively
TestMemory.java
which contains a small program to test
your code.
Test your implementation by running the Java interpreter on the class
TestMemory
. A successful execution of the test program
should produce the following output:
Fetch from location 34 = 0 Store Data(17) in location 34 Store Address(5000) in location 200 Fetch from location 34 = 17 Fetch from location 200 = 5000 Fetching from bad address = duckMachine.architecture.MemoryE: Address 5000 is out of range
Turn in the code for Memory.java
during class on Monday,
April 19th. Write the lab (day and time) that you are attending on top
of your assignment in addition to your name and SS#.
Last modified: 04/05/99 01:35:25
yreimer@cs.uoregon.edu