-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemory.java
More file actions
60 lines (50 loc) · 1.06 KB
/
Memory.java
File metadata and controls
60 lines (50 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public class Memory
{
// tape has 2^16 individual cells
private static final int TAPE_SIZE = 65536;
private int pointer;
private long[] valuePointedBy;
// memory constructor
public Memory()
{
valuePointedBy = new long[TAPE_SIZE];
pointer = 0;
}
// trivial methods to abstract tape operations
public void incrementCurrentCell()
{
valuePointedBy[pointer]++;
}
public void decrementCurrentCell()
{
valuePointedBy[pointer]--;
}
public void incrementPointer()
{
pointer++;
}
public void decrementPointer()
{
pointer--;
}
public int getCurrentCell()
{
return pointer;
}
public long getCurrentCellValue()
{
return valuePointedBy[pointer];
}
public void setCurrentCellValue(long newValue)
{
valuePointedBy[pointer] = newValue;
}
public String toString()
{
return "("
+ pointer
+ ", "
+ valuePointedBy[pointer]
+ ")";
}
}