-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.v
131 lines (118 loc) · 3.14 KB
/
control.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
130
131
module control (clk, reset,Op, Zero, IorD, MemRead, MemWrite, MemtoReg, IRWrite,
PCSource, ALUSrcB, ALUSrcA, RegWrite, RegDst, PCSel, ALUOp);
input clk;
input reset;
input [3:0] Op;
input Zero;
output reg IorD;
output reg MemWrite;
output reg MemRead;
output reg MemtoReg;
output reg IRWrite;
output reg PCSource;
output reg RegDst;
output reg RegWrite;
output reg ALUSrcA;
output reg [1:0] ALUSrcB;
output PCSel;
output reg [1:0] ALUOp;
reg PCWrite;
reg PCWriteCond;
assign
PCSel = (PCWrite | (PCWriteCond & Zero));
//states
parameter FETCH = 4'b0000;
parameter DECODE = 4'b0001;
parameter MEMADRCOMP = 4'b0010;
parameter MEMACCESSL = 4'b0011;//L1
parameter MEMREADEND = 4'b0100;//L2
parameter MEMACCESSS = 4'b0101;//S
parameter EXECUTION = 4'b0110;
parameter RTYPEEND = 4'b0111;
parameter BEQ = 4'b1000;
reg [3:0] state;
reg [3:0] nextstate;
always@(posedge clk)
if (reset)
state <= FETCH;
else
state <= nextstate;
always@(state or Op) begin
case (state)
FETCH: nextstate = DECODE;
DECODE: case(Op)
//OpCode
4'b1010: nextstate = MEMADRCOMP;//LW
4'b1001: nextstate = MEMADRCOMP;//SW
4'b00x0: nextstate = EXECUTION; // ADD or ADC or NDU or NDZ
4'b1011: nextstate = BEQ;//BEQ
default: nextstate = FETCH;
endcase
MEMADRCOMP: case(Op)
6'b100011: nextstate = MEMACCESSL;//lw
6'b101011: nextstate = MEMACCESSS;//sw
default: nextstate = FETCH;
endcase
MEMACCESSL: nextstate = MEMREADEND;
MEMREADEND: nextstate = FETCH;
MEMACCESSS: nextstate = FETCH;
EXECUTION: nextstate = RTYPEEND;
RTYPEEND: nextstate = FETCH;
BEQ: nextstate = FETCH;
default: nextstate = FETCH;
endcase
end
always@(state) begin
IorD=1'b0; MemRead=1'b0; MemWrite=1'b0; MemtoReg=1'b0; IRWrite=1'b0; PCSource=1'b0;
ALUSrcB=2'b00; ALUSrcA=1'b0; RegWrite=1'b0; RegDst=1'b0; PCWrite=1'b0; PCWriteCond=1'b0; ALUOp=2'b00;
case (state)
FETCH:
begin
MemRead = 1'b1;
IRWrite = 1'b1;
ALUSrcB = 2'b01;
PCWrite = 1'b1;
end
DECODE:
ALUSrcB = 2'b11;
MEMADRCOMP:
begin
ALUSrcA = 1'b1;
ALUSrcB = 2'b10;
end
MEMACCESSL:
begin
MemRead = 1'b1;
IorD = 1'b1;
end
MEMREADEND:
begin
RegWrite = 1'b1;
MemtoReg = 1'b1;
RegDst = 1'b0;
end
MEMACCESSS:
begin
MemWrite = 1'b1;
IorD = 1'b1;
end
EXECUTION:
begin
ALUSrcA = 1'b1;
ALUOp = 2'b10;
end
RTYPEEND:
begin
RegDst = 1'b1;
RegWrite = 1'b1;
end
BEQ:
begin
ALUSrcA = 1'b1;
ALUOp = 2'b01;
PCWriteCond = 1'b1;
PCSource = 2'b01;
end
endcase
end
endmodule