-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemory.java
More file actions
50 lines (46 loc) · 1.74 KB
/
Memory.java
File metadata and controls
50 lines (46 loc) · 1.74 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
//package SYSTEM;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
public class Memory {
// The MEMORY subsystem is called from SYSTEM so as to read from or write
// into memory while executing the user job in CPU subsystem.
// parameter X denotes the READ, WRITE or DUMP instruction.
// parameter Y denotes the memory address register.
// parameter Z denotes the memory buffer register.
void MEMORY1(SYSTEM system,int X, int Y, int Z) throws Exception {
if (X == 0x11) // DUMP instruction semantics are executed
{
int j = 0, l = 0, m = 0;
int actualIteration = 0;
File file = new File("PROGRESS_FILE.txt");
FileWriter fileWritter = new FileWriter(file.getName(), true);
BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
bufferWritter.write("Output of the Dump instruction of job : " + system.outerList.get(2).get(0));
bufferWritter.newLine();
actualIteration = system.maxPhysicalIndex / 8 + 1;
for (int k = 0; k < actualIteration; k++) {
bufferWritter.write((String.format("%04x", m)).toUpperCase());
j = 0;
m = m + 8;
while (j < 8 && l <= system.maxPhysicalIndex) {
bufferWritter.write(" " + String.format("%08x", system.MEM[l]).toUpperCase() + " ");
l++;
j++;
}
bufferWritter.newLine();
}
bufferWritter.close();
} else {
for (int k = Y; k <= Z; k++) {
int index = (k >> 4) & 0x7;
int pageTableValue = system.PageTable[index];
int address = (k) & 0xf;
system.physicalIndex = (pageTableValue << 4) | address;
system.MEM[system.physicalIndex] = system.VirtualMem[k];
if (system.maxPhysicalIndex < system.physicalIndex)
system.maxPhysicalIndex = system.physicalIndex;
}
}
}
}