/* * Created on Feb 21, 2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author brooks * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class MainMemory { /** * */ private int memory[]; private int maxaddr = -1; public MainMemory() { super(); memory = new int[10]; } public int getData(int loc) { if (loc < 0 || loc > 9) { System.out.println("Error accessing memory: invalid address."); return 0; } else { return memory[loc]; } } public void setData(int data, int loc) { if (loc < 0 || loc > 9) { System.out.println("Error accessing memory: invalid address."); } else { memory[loc] = data; } } public void printSelf() { for (int i = 0; i < 10; i++) { System.out.println(i + " " + memory[i]); } } public int getNextAddr() { maxaddr++; return maxaddr; } }