-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol_unit.v
More file actions
125 lines (106 loc) · 2.29 KB
/
control_unit.v
File metadata and controls
125 lines (106 loc) · 2.29 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
`timescale 1ns / 1ps
module control_unit
(
input[4:0] opcode,
input reset,
output reg[2:0] alu_op,
output reg jump, branch, mem_read, mem_write, // control signals
alu_src, reg_write, reg_dst,
call, shift_reg, jump_reg
);
always @(*)
begin
if(reset == 1'b1)
begin
reg_dst = 1'b0;
alu_op = 3'b000;
jump = 1'b0;
branch = 1'b0;
mem_read = 1'b0;
mem_write = 1'b0;
alu_src = 1'b0;
reg_write = 1'b0;
call = 1'b0;
jump_reg = 1'b0;
shift_reg = 1'b0;
end
else
begin
reg_dst = 1'b0;
jump = 1'b0;
branch = 1'b0;
mem_read = 1'b0;
mem_write = 1'b0;
alu_src = 1'b0;
call = 1'b0;
jump_reg = 1'b0;
shift_reg = 1'b0;
reg_write = 1'b1;
alu_op = opcode[4:2];
if(opcode[0] == 1'b0) // regdst
begin
reg_dst = 1'b1;
end
else // alu_src
begin
alu_src = 1'b1;
end
if(opcode[1] == 1'b1) // jump
begin
jump = 1'b1;
end
case(opcode)
// R-Format
5'b01010: begin // jr
jump_reg = 1'b1;
reg_write = 1'b0;
end
5'b10110: begin // syscall
reg_dst = 1'b0;
call = 1'b1;
reg_write = 1'b0;
jump = 1'b0;
end
// I-Format
5'b10101: begin // lui
shift_reg = 1'b1;
end
5'b00101: begin // beq
branch = 1'b1;
alu_src = 1'b0;
reg_write = 1'b0;
end
5'b01101: begin // bne
reg_dst = 1'b1;
branch = 1'b1;
alu_src = 1'b0;
reg_write = 1'b0;
alu_op = 3'b001;
end
5'b00001: begin // sw
mem_write = 1'b1;
reg_write = 1'b0;
end
5'b01001: begin // lw
mem_read = 1'b1;
alu_op = 3'b000;
end
// J-Format
5'b00010: begin // jal
jump = 1'b1;
end
5'b00110: begin // j
mem_read = 1'b1;
reg_write = 1'b0;
end
// exit:
5'b11111: begin
reg_write = 1'b0;
alu_op = 3'bx;
alu_src = 1'b0;
jump = 1'b0;
end
endcase
end
end
endmodule