-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControl.java
81 lines (77 loc) · 1.48 KB
/
Control.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
81
/*
* This class is simply used to set enable flags depending on the opcode from the instruction provided.
*/
public class Control {
boolean regWrite;
boolean memWrite;
boolean memRead;
boolean memToReg;
boolean reg2Loc;
Processor p;
public Control(Processor _p) {
regWrite = memWrite = memRead = memToReg = reg2Loc = false;
this.p = _p;
}
public void process(String opcode) {
p.alu.aluOp = opcode;
switch (opcode) {
case "00001": // SET
regWrite = true;
memWrite = true;
memRead = false;
reg2Loc = false;
memToReg = true;
break;
case "00010": // GET
regWrite = false;
memWrite = true;
memRead = false;
reg2Loc = true;
memToReg = true;
break;
case "00011": // MOVE
regWrite = true;
memWrite = true;
memRead = false;
reg2Loc = false;
memToReg = true;
break;
case "00100":
case "00101":
case "00110":
case "00111":
case "01000":
case "01001":
case "01010":
case "01011":
case "01100":
case "01101":
case "01110":
case "01111":
case "10000":
case "10001":
case "10010":
case "10011":
case "10100":
case "10101":
case "10110":
case "11000":
case "11001":
case "11010":
case "11011":
regWrite = true;
memWrite = false;
memRead = true;
reg2Loc = false;
memToReg = false;
break;
case "10111": // NOP
regWrite = true;
memWrite = true;
memRead = false;
reg2Loc = true;
memToReg = false;
break;
}
}
}