-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteBack.c
108 lines (104 loc) · 4.26 KB
/
writeBack.c
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
/*
* @author matthewspydell
*/
#include "writeBack.h"
void writeBack() {
if (printing) {
printf("\nWrite Back Stage\n");
}
if (MEM_WB.rd == 0) {
MEM_WB.moveControl = 0;
}
if (MEM_WB.moveControl == 1) {
switch (MEM_WB.opcode) {
case 0x1F: // sign-extend byte
R[MEM_WB.rd] = MEM_WB.aluOutput;
if (printing) {
printf("ALU Output = %d\n", MEM_WB.aluOutput);
printf("R[%d] = %d\n", MEM_WB.rd, R[MEM_WB.rd]);
}
break;
case 0x00: // R-format
R[MEM_WB.rd] = MEM_WB.aluOutput;
if (printing) {
printf("ALU Output = %d\n", MEM_WB.aluOutput);
printf("R[%d] = %d\n", MEM_WB.rd, R[MEM_WB.rd]);
}
break;
case 0x08: // add immediate, R[rt] = R[rs] + imm (signed)
R[MEM_WB.rd] = MEM_WB.aluOutput;
if (printing) {
printf("ALU Output = %d\n", MEM_WB.aluOutput);
printf("R[%d] = %d\n", MEM_WB.rd, R[MEM_WB.rd]);
}
break;
case 0x09: // add immediate, R[rt] = R[rs] + imm (unsigned)
R[MEM_WB.rd] = MEM_WB.aluOutput;
if (printing) {
printf("ALU Output = %d\n", MEM_WB.aluOutput);
printf("R[%d] = %d\n", MEM_WB.rd, R[MEM_WB.rd]);
}
break;
case 0x0C: // and immediate, R[rt] = R[rs] & imm (zero extended)
R[MEM_WB.rd] = MEM_WB.aluOutput;
if (printing) {
printf("ALU Output = %d\n", MEM_WB.aluOutput);
printf("R[%d] = %d\n", MEM_WB.rd, R[MEM_WB.rd]);
}
break;
case 0x24: // load byte, R[rt] = MEM8(R[rs] + imm) (unsigned)
R[MEM_WB.rd] = MEM_WB.aluOutput;
if (printing) {
printf("ALU Output = %d\n", MEM_WB.aluOutput);
printf("R[%d] = %d\n", MEM_WB.rd, R[MEM_WB.rd]);
}
break;
case 0x25: // load halfword, R[rt] = MEM16(R[rs] + imm) (unsigned)
R[MEM_WB.rd] = MEM_WB.aluOutput;
if (printing) {
printf("ALU Output = %d\n", MEM_WB.aluOutput);
printf("R[%d] = %d\n", MEM_WB.rd, R[MEM_WB.rd]);
}
break;
case 0x23: // load word, R[rt] = MEM16(R[rs] + imm)
R[MEM_WB.rd] = MEM_WB.aluOutput;
if (printing) {
printf("ALU Output = %d\n", MEM_WB.aluOutput);
printf("R[%d] = %d\n", MEM_WB.rd, R[MEM_WB.rd]);
}
break;
case 0x0D: // or immediate, R[rt] = R[rs] | imm (zero extended)
R[MEM_WB.rd] = MEM_WB.aluOutput;
if (printing) {
printf("ALU Output = %d\n", MEM_WB.aluOutput);
printf("R[%d] = %d\n", MEM_WB.rd, R[MEM_WB.rd]);
}
break;
case 0x0A: // set less than, R[rt] = (R[rs] < imm) ? 1:0 (signed)
R[MEM_WB.rd] = MEM_WB.aluOutput;
if (printing) {
printf("ALU Output = %d\n", MEM_WB.aluOutput);
printf("R[%d] = %d\n", MEM_WB.rd, R[MEM_WB.rd]);
}
break;
case 0x0B: // set less than, R[rt] = (R[rs] < imm) ? 1:0 (unsigned)
R[MEM_WB.rd] = MEM_WB.aluOutput;
if (printing) {
printf("ALU Output = %d\n", MEM_WB.aluOutput);
printf("R[%d] = %d\n", MEM_WB.rd, R[MEM_WB.rd]);
}
break;
/*
case 0x28: // store byte, MEM8(R[rs] + imm) = R[rt]
R[MEM_WB.rd] = MEM_WB.aluOutput;
break;
case 0x29: // store halfword, MEM16(R[rs] + imm) = R[rt]
R[MEM_WB.rd] = MEM_WB.aluOutput;
break;
case 0x2B: // store word, MEM32(R[rs] + imm) = R[rt]
R[MEM_WB.rd] = MEM_WB.aluOutput;
break;
*/
}
}
}