-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomAccessMemory.java
More file actions
54 lines (47 loc) · 1.26 KB
/
RandomAccessMemory.java
File metadata and controls
54 lines (47 loc) · 1.26 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
public class RandomAccessMemory{
private Memory[] memory;
private Bit8 data;
/**
* Class constructor for the RAM
* @param memory an array that store the memory string
*/
public RandomAccessMemory(String[] memory) {
this.memory = new Memory[16];
for (int i = 0; i < 16; i++) {
String mem = memory[i];
if (!mem.equals("")) {
this.memory[i] = new Memory(mem);
}
}
}
/**
* Setter for the data
* @param bit4 the Bit4 data taht will be changed to decimal number
*/
private void setData(Bit4 bit4) {
this.data = this.memory[bit4.toDecimal()].getData();
}
/**
* Getter for the data
* @return the data value
*/
private Bit8 getData() {
return this.data;
}
public Bit8 getFromMemory(Bit4 index){
setData(index);
return getData();
}
private class Memory {
private final Bit8 data;
/** Class constructor
* @param data the data taht will be created based on Bit* data type
*/
private Memory(String data) {
this.data = new Bit8(data);
}
private Bit8 getData(){
return this.data;
}
}
}