-
Notifications
You must be signed in to change notification settings - Fork 1
/
Execute.java
80 lines (70 loc) · 1.48 KB
/
Execute.java
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.util.*;
public class Execute {
private int result;
private int dest;
public Execute() {
}
public void doExecute(String instType, int op1, int op2) {
int answer;
switch (instType) {
case "LOAD":
if(op2 < -99) {
this.result = -99;
WriteBack.setOF(1);
}else if (op2 > 99) {
this.result = 99;
WriteBack.setOF(1);
}else {
this.result = op2;
WriteBack.setOF(0);
}
this.dest = op1;
break;
case "ADD":
answer = WriteBack.getRegister(op1) + WriteBack.getRegister(op2);
if(answer < -99) {
this.result = -99;
WriteBack.setOF(1);
}else if (answer > 99) {
this.result = 99;
WriteBack.setOF(1);
}else {
this.result = answer;
WriteBack.setOF(0);
}
this.dest = op1;
break;
case "SUB":
answer = WriteBack.getRegister(op1) - WriteBack.getRegister(op2);
if(answer < -99) {
this.result = -99;
WriteBack.setOF(1);
}else if (answer > 99) {
this.result = 99;
WriteBack.setOF(1);
}else {
this.result = answer;
WriteBack.setOF(0);
}
this.dest = op1;
break;
case "CMP":
answer = WriteBack.getRegister(op1) - WriteBack.getRegister(op2);
if(answer == 0) {
WriteBack.setZF(1);
WriteBack.setNF(0);
}else if (answer < 0) {
WriteBack.setZF(0);
WriteBack.setNF(1);
}
this.dest = -1;
break;
}
}
public int getResult() {
return this.result;
}
public int getDest() {
return this.dest;
}
}