-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlUnit.v
129 lines (103 loc) · 4.18 KB
/
ControlUnit.v
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
`include "Defines.v"
module ControlUnit(
mode, opcode, s, immediate_in,
execute_command, mem_read, mem_write,
wb_enable, immediate,
branch_taken, status_write_enable, ignore_hazard
);
input[`MODE_LEN - 1 : 0] mode;
input[`OPCODE_LEN - 1 : 0] opcode;
input s, immediate_in;
output wire[`EXECUTE_COMMAND_LEN - 1 : 0] execute_command;
output wire mem_read, mem_write, immediate,
wb_enable, branch_taken, status_write_enable, ignore_hazard;
reg mem_read_reg, mem_write_reg,
wb_enable_reg, branch_taken_reg, status_write_enable_reg, ignore_hazard_reg;
reg [`EXECUTE_COMMAND_LEN - 1 : 0] execute_command_reg;
// @TODO: What shoult I do
assign immediate = immediate_in;
assign status_write_enable = s;
assign execute_command = execute_command_reg;
assign mem_read = mem_read_reg;
assign mem_write = mem_write_reg;
assign wb_enable = wb_enable_reg;
assign branch_taken = branch_taken_reg;
assign ignore_hazard = ignore_hazard_reg;
always @(mode, opcode, s) begin
mem_write_reg = `DISABLE;
mem_read_reg = `DISABLE;
wb_enable_reg = `DISABLE;
branch_taken_reg = `DISABLE;
ignore_hazard_reg = `DISABLE;
case (mode)
`ARITHMETHIC_TYPE : begin
case(opcode)
`MOV : begin
wb_enable_reg = `ENABLE;
execute_command_reg = `MOV_EXE;
ignore_hazard_reg = `ENABLE;
end
`MOVN : begin
wb_enable_reg = `ENABLE;
execute_command_reg = `MOVN_EXE;
ignore_hazard_reg = `ENABLE;
end
`ADD : begin
wb_enable_reg = `ENABLE;
execute_command_reg = `ADD_EXE;
end
`ADC : begin
wb_enable_reg = `ENABLE;
execute_command_reg = `ADC_EXE;
end
`SUB : begin
wb_enable_reg = `ENABLE;
execute_command_reg = `SUB_EXE;
end
`SBC : begin
wb_enable_reg = `ENABLE;
execute_command_reg = `SBC_EXE;
end
`AND : begin
wb_enable_reg = `ENABLE;
execute_command_reg = `AND_EXE;
end
`ORR : begin
wb_enable_reg = `ENABLE;
execute_command_reg = `ORR_EXE;
end
`EOR : begin
wb_enable_reg = `ENABLE;
execute_command_reg = `EOR_EXE;
end
`CMP :
execute_command_reg = `CMP_EXE;
`TST :
execute_command_reg = `TST_EXE;
`LDR : begin
wb_enable_reg = `ENABLE;
execute_command_reg = `LDR_EXE;
end
`STR :
execute_command_reg = `STR_EXE;
endcase
end
`MEMORY_TYPE : begin
execute_command_reg = `ADD_EXE;
case (s)
`S_ONE : begin
mem_read_reg = `ENABLE;
wb_enable_reg = `ENABLE;
end
`S_ZERO : begin
mem_write_reg = `ENABLE;
end
endcase
end
`BRANCH_TYPE : begin
branch_taken_reg = `ENABLE;
ignore_hazard_reg = `ENABLE;
end
endcase
end
endmodule