Package lab06
Class Memory
java.lang.Object
lab06.Memory
public class Memory
extends java.lang.Object
Model a RAM memory for Pippin.
A Pippin memory is simply an indexed array of data values.
The index is treated as the memory address.
Each value at each address may be written - replaced by a new integer value,
or read, return the value at that location.
- Author:
- cs140
-
Constructor Summary
Constructors Constructor Description Memory(int length)Construct a new Pippin Memory whose size is specified by the parameter. -
Method Summary
Modifier and Type Method Description voiddump(java.lang.String title)Prints out the title and the contents of the entire memory.voiddump(java.lang.String title, int start, int stop)Prints out the title and the contents of memory from the specified start location to the specified stop location.intget(int loc)Retrieves and returns the value at the specified location.voidset(int loc, int val)Writes the val parameter to the location in the loc parameter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Memory
public Memory(int length)Construct a new Pippin Memory whose size is specified by the parameter.- Parameters:
length- number of locations in the memory
-
-
Method Details
-
set
public void set(int loc, int val)Writes the val parameter to the location in the loc parameter. If the location is invalid, prints an error message and does not update memory.- Parameters:
loc- index into the memory to write a new valueval- value to write to the specified location
-
get
public int get(int loc)Retrieves and returns the value at the specified location. If the loc is not valid, writes a message and returns a -1 value- Parameters:
loc- index into the memory to write a new value- Returns:
- the value at the specified location
-
dump
public void dump(java.lang.String title)Prints out the title and the contents of the entire memory.- Parameters:
title- a String to identify this dump of memory
-
dump
public void dump(java.lang.String title, int start, int stop)Prints out the title and the contents of memory from the specified start location to the specified stop location.- Parameters:
title- a String to identify this dump of memorystart- index of the first location to dumpstop- index of the last location to dump
-