-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCONTROL.v.bak
188 lines (148 loc) · 2.51 KB
/
CONTROL.v.bak
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
module CONTROL (in, clk, rst, out);
input [16:0]in;
input clk, rst;
output
wire [31:0]ARcarry;
reg memrw;
reg memin;
wire memout;
reg [31:0]memaddr;
reg memaddrs;
wire regi;
wire [1:0]regs;
reg pcrw;
reg pcin;
wire pcout;
reg pcs;
wire bpc;
reg regin;
reg regins;
reg reginc;
reg regrw;
reg regaddr0;
reg regaddr1;
reg regout0;
reg regout1;
//wire statupd8;
reg [7:0]aluinst;
wire [31:0]aluA;
wire [31:0]aluB;
wire [31:0]aluO;
wire statupd8;
reg [7:0] inst;
ALU alu (aluinst, aluA, aluB, aluO, statupd8);
REGFILE regfile (regin, regout0, regout1, regaddr0, regaddr1, regrw, clk, rst);
REGFILE mem (memin, memout, memout, memaddr, memaddr, memrw, clk, rst);
REG pc (pcrw, pcin, pcout, clk, rst);
reg [3:0]State, NState;
parameter ADD = 8'd2,
SUB = 8'd3,
MEMW = 8'd4,
MEMR = 8'd5,
CP = 8'd6,
MV = 8'd7,
BEQ = 8'd0,
BLT = 8'd1;
parameter FETCH = 3'd0,
DECODE = 3'd1,
EXECUTE = 3'd2,
UPDATE = 3'd3,
INPUT = 3'd4;
always @(posedge clk or negedge rst)
begin
if(rst == 1'd0) begin
State <= INPUT;
end
else begin
State <= NState;
end
end
//Finite State Machine
always @(*) begin
case(State)
FETCH: begin
NState = DECODE;
end
DECODE: begin
NState = EXECUTE;
end
EXECUTE: begin
NState = UPDATE;
end
UPDATE: begin
NState = FETCH;
end
default: begin
end
endcase
end
reg [31:0]instFetch;
always @(posedge clk or negedge rst) begin
if(rst == 1'd0) begin
pcin <= 32'd0;
pcrw <= 1'd1;
regins <= 2'd1;
reginc <= 32'd0;
regaddr0 <= 32'd0;
regaddr1 <= 32'd0;
regrw <= 1'd0;
memin <= 32'd0;
memaddrs <= 1'd0;
aluinst <= 8'd0;
end
else begin
case(State)
FETCH: begin
regrw <= 1'd0;
memaddr <= pcout;
memrw <= 1'd0;
instFetch <= memout;
end
DECODE: begin
inst <= instFetch[31:24];
if (inst == MV) begin
regaddr1 <= instFetch[23:16];
regaddr0 <= instFetch[15:8];
end
end
EXECUTE: begin
if(inst == MV) begin
regrw <= 1'd1;
end
end
UPDATE: begin
if(inst == MV)
pcs <= 1'd0;
pcin <= pcout + 1;
end
endcase
end
end
//MUXes
always @(*) begin
/**/
case(memaddrs)//Mem address switch
1'd0: begin //Pass-through the pc as usual
memaddr = pcout;
end
1'd1: begin //Pass-through the register for a specific memory allocation
memaddr = regout0;
end
endcase
/**/
case(regins)//RegFile input switch
2'd0: begin //Input the ALU mathematical output
regin = aluO;
end
2'd1: begin //Input a special value from the Control
regin = reginc;
end
2'd2: begin //Input the memory output
regin = memout;
end
2'd3: begin //Input the RegFile secondary output
regin = regout1;
end
endcase
end
endmodule