-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol_unit.v
More file actions
138 lines (123 loc) · 2.77 KB
/
control_unit.v
File metadata and controls
138 lines (123 loc) · 2.77 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Assignment 7
//
//Group No.42
//Members: Seemant Guruprasad Achari 19CS10055
// Chappidi Yoga Satwik 19CS30013
//
// The following module is to send out control signals to various multiplexers and
// other modules. It recieves as input the functCode and the opCode from the instruction
//
//////////////////////////////////////////////////////////////////////////////////
module control_unit(CondBr,
RegBr,
UncondBr,
MemRead,
MemWrite,
WriteReg,
ALUSrc,
WriteSrc,
RegDst,
UncondControl,
CondControl,
ALUOp,
opCode,
functCode
);
input [5:0] opCode;
input [7:0] functCode;
output reg CondBr, RegBr,UncondBr, MemRead, MemWrite, WriteReg, ALUSrc, RegDst;
output reg [1:0] WriteSrc, UncondControl, CondControl;
output reg [2:0] ALUOp;
always@(opCode or functCode) begin
//condBr
if(opCode==6'b000110 || opCode==6'b000111 || opCode==6'b001000)
CondBr=1'b1;
else CondBr=1'b0;
//uncondBr
if(opCode==6'b100101 || opCode==6'b100110 || opCode==6'b100111 || opCode==6'b101000)
UncondBr=1'b1;
else UncondBr=1'b0;
//RegBr
if(opCode==6'b000000 && functCode==8'b00100000)
RegBr=1'b1;
else RegBr=1'b0;
//MemWrite
if(opCode==6'b100001)
MemWrite=1'b1;
else MemWrite=1'b0;
//MemRead
if(opCode==6'b100000 || opCode==6'b100001)
MemRead=1'b1;
else MemRead=1'b0;
//WriteReg
if(opCode==6'b000000)
begin
if(functCode==8'b00100000 || functCode==8'b00000000)
WriteReg=1'b0;
else WriteReg=1'b1;
end
else if(opCode==6'b100000)
WriteReg=1'b1;
else if(opCode==6'b000001)
WriteReg=1'b1;
else if(opCode==6'b000010)
WriteReg=1'b1;
else if(opCode==6'b000011)
WriteReg=1'b1;
else if(opCode==6'b100110)
WriteReg=1'b1;
else if(opCode==6'b000100)
WriteReg=1'b1;
else if(opCode==6'b000101)
WriteReg=1'b1;
else WriteReg=1'b0;
//ALUSrc
if(opCode==6'b000000)
ALUSrc=1'b1;
else ALUSrc=1'b0;
//RegDst
if(opCode==6'b100110)
RegDst=1'b0;
else RegDst=1'b1;
//WriteSrc
if(opCode==6'b000000)
begin
WriteSrc=2'b10;
end
else if(opCode==6'b100110)
WriteSrc=2'b00;
else if(opCode==6'b100000)
WriteSrc=2'b01;
else WriteSrc=2'b10;
//UncondControl
if(opCode==6'b100101 || opCode==6'b100110)
UncondControl=2'b01;
else if(opCode==6'b100111)
UncondControl=2'b11;
else UncondControl=2'b10;
//CondControl
if(opCode==6'b000110)
CondControl=2'b10;
else if(opCode==6'b000111)
CondControl=2'b11;
else CondControl=2'b01;
//ALUOp
if(opCode==6'b000000)
ALUOp=3'b000;
else if(opCode==6'b100000 || opCode==6'b100001)
ALUOp=3'b101;
else if(opCode==6'b000001)
ALUOp=3'b101;
else if(opCode==6'b000010)
ALUOp=3'b110;
else if(opCode==6'b000011)
ALUOp=3'b010;
else if(opCode==6'b000100)
ALUOp=3'b011;
else if(opCode==6'b000101)
ALUOp=3'b100;
else ALUOp=3'b001;
end
endmodule