-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathControl_Unit.v
More file actions
89 lines (68 loc) · 1.98 KB
/
Control_Unit.v
File metadata and controls
89 lines (68 loc) · 1.98 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
`timescale 1ns / 1ps
module Control_Unit(op, RegWrite, ALUSrc, MEM, RegOrSign, ALUorMEM, Jump);
input [2:0]op;
output reg [2:0]RegWrite; // gives OP code to RegMod to perform operations
output reg ALUSrc; // determines adding or subtracting for the ALU
output reg MEM; // signifies read or write for DataMEM
output reg RegOrSign; // either take signextend from instruction or Register value from register file
output reg ALUorMEM; // determines writeback value between ALU output or DataMEM output
output reg Jump; // determines if we jump to an address or +1 to next instuction
always @* begin
case(op)
3'b100: begin
//add op = 100
RegWrite = 3'b001;
ALUSrc = 1'b1; //1 == add
RegOrSign = 1'b0;
ALUorMEM = 1'b0;
Jump = 1'b0;
end
3'b101: begin
//addi
RegWrite = 3'b100;
ALUSrc = 1'b1;
RegOrSign = 1'b1;
ALUorMEM = 1'b0;
Jump = 1'b0;
end
3'b110: begin
//sub
RegWrite = 3'b010;
ALUSrc = 1'b0;
RegOrSign = 1'b0;
ALUorMEM = 1'b0;
Jump = 1'b0;
end
3'b001: begin
//lw
RegWrite = 3'b011;
ALUSrc = 1'b1;
MEM = 1'b1;
RegOrSign = 1'b1;
ALUorMEM = 1'b1;
Jump = 1'b0;
//MEM 1 = read
//MEM 0 = write
end
3'b010: begin
//sw
RegWrite = 3'b000;
ALUSrc = 1'b1;
MEM = 1'b0;
RegOrSign = 1'b1;
ALUorMEM = 1'b0;
Jump = 1'b0;
//MEM 1 = read
//MEM 0 = write
end
3'b011: begin
//jump
RegWrite = 3'b000;
ALUSrc = 1'b0;
RegOrSign = 1'b1;
ALUorMEM = 1'b0;
Jump = 1'b1;
end
endcase
end
endmodule