-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimProcessor.java
More file actions
60 lines (52 loc) · 1.52 KB
/
SimProcessor.java
File metadata and controls
60 lines (52 loc) · 1.52 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
import java.util.Random;
public class SimProcessor {
Random r = new Random(); //using random numbers to represent the values be processed
private SimProcess currentProcess;
private int R1, R2, R3, R4, currInstruction;
public void setCurrentProcess(SimProcess currentProcess) {
this.currentProcess = currentProcess;
}
public SimProcess getCurrentProcess() {
return currentProcess;
}
public void setRegisterValue(int register, int value) {
if (register == 1) {
R1 = value;
}
if (register == 2) {
R2 = value;
}
if (register == 3) {
R3 = value;
}
if (register == 4) {
R4 = value;
}
}
public int getRegisterValues(int register) {
if (register == 1) {
return R1;
}
if (register == 2) {
return R2;
}
if (register == 3) {
return R3;
}
return R4;
}
public void setCurrInstruction(int currInstruction) {
this.currInstruction = currInstruction;
}
public int getCurrInstruction() {
return currInstruction;
}
public Main.ProcessState executeNextInstruction() {
Main.ProcessState currentProcessState = currentProcess.execute(currInstruction++);
R1 = r.nextInt();
R2 = r.nextInt();
R3 = r.nextInt();
R4 = r.nextInt();
return currentProcessState;
}
}