-
Notifications
You must be signed in to change notification settings - Fork 2
/
control.cpp
120 lines (94 loc) · 2.15 KB
/
control.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "control.h"
/**
* \c control module callback function.
*/
void control::entry()
{
jbr.write(0);
switch(opcode.read()) {
case 0: // R-format
RegDst.write(1);
ALUSrc.write(0);
MemtoReg.write(0);
RegWrite.write(1);
MemRead.write(0);
MemWrite.write(0);
switch(funct.read()) {
case 8: jbr.write(6); // jr
break;
case 32: ALUOp.write(2); // add
break;
case 34: ALUOp.write(6); // subtract
break;
case 36: ALUOp.write(0); // bitwise AND
break;
case 37: ALUOp.write(1); // Bitwise OR
break;
case 42: ALUOp.write(7); // Set to 1 if Less Than
break;
}
break;
case 2: // j
ALUSrc.write(0);
RegWrite.write(0);
MemRead.write(0);
MemWrite.write(0);
ALUOp.write(6);
jbr.write(5);
break;
case 4: // beq
ALUSrc.write(0);
RegWrite.write(0);
MemRead.write(0);
MemWrite.write(0);
ALUOp.write(6);
jbr.write(1);
break;
case 5: // bne
ALUSrc.write(0);
RegWrite.write(0);
MemRead.write(0);
MemWrite.write(0);
ALUOp.write(6);
jbr.write(2);
break;
case 6: // blez
ALUSrc.write(0);
RegWrite.write(0);
MemRead.write(0);
MemWrite.write(0);
ALUOp.write(6);
jbr.write(4);
break;
case 7: // bgtz
ALUSrc.write(0);
RegWrite.write(0);
MemRead.write(0);
MemWrite.write(0);
ALUOp.write(6);
jbr.write(3);
break;
case 35: // lw
RegDst.write(0);
ALUSrc.write(1);
MemtoReg.write(1);
RegWrite.write(1);
MemRead.write(1);
MemWrite.write(0);
ALUOp.write(2);
jbr.write(0);
break;
case 43: // sw
ALUSrc.write(1);
RegWrite.write(0);
MemRead.write(0);
MemWrite.write(1);
ALUOp.write(2);
jbr.write(0);
break;
default: // Unknown opcode
fprintf(stderr,"ERROR: Illegal opcode\n");
//assert(0);
break;
}
}