Skip to content

Commit 7caceaf

Browse files
committed
Merge branch 'master' of github.com:mr-bat/Computer_Architecture_Lab
2 parents 7989a2d + 0172519 commit 7caceaf

File tree

7 files changed

+88
-74
lines changed

7 files changed

+88
-74
lines changed

Sec_8/EXE_Reg.v

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module EXE_Stage_reg
33
(
44
clk,
55
rst,
6+
stall,
67
PC_in,
78
WB_En_in,
89
MEM_R_En_in,
@@ -22,10 +23,11 @@ module EXE_Stage_reg
2223
Immediate,
2324
ALU_result
2425
);
25-
26+
2627
// input and output ports
2728
input clk;
2829
input rst;
30+
input stall;
2931
input WB_En_in;
3032
input MEM_R_En_in;
3133
input MEM_W_En_in;
@@ -44,7 +46,7 @@ module EXE_Stage_reg
4446
output [31:0] PC;
4547
output [31:0] Immediate;
4648
output [31:0] ALU_result;
47-
49+
4850
// registers
4951
reg WB_En;
5052
reg MEM_R_En;
@@ -55,7 +57,7 @@ module EXE_Stage_reg
5557
reg [31:0] PC;
5658
reg [31:0] Immediate;
5759
reg [31:0] ALU_result;
58-
60+
5961
// build module
6062
always @(posedge clk)
6163
begin
@@ -73,16 +75,18 @@ module EXE_Stage_reg
7375
end
7476
else
7577
begin
76-
dest <= dest_in;
77-
PC <= PC_in;
78-
WB_En <= WB_En_in;
79-
MEM_R_En <= MEM_R_En_in;
80-
MEM_W_En <= MEM_W_En_in;
81-
Is_Imm <= Is_Imm_in;
82-
readdata <= readdata_in;
83-
Immediate <= Immediate_in;
84-
ALU_result <= ALU_result_in;
78+
if (~stall) begin
79+
dest <= dest_in;
80+
PC <= PC_in;
81+
WB_En <= WB_En_in;
82+
MEM_R_En <= MEM_R_En_in;
83+
MEM_W_En <= MEM_W_En_in;
84+
Is_Imm <= Is_Imm_in;
85+
readdata <= readdata_in;
86+
Immediate <= Immediate_in;
87+
ALU_result <= ALU_result_in;
88+
end
8589
end
8690
end
87-
91+
8892
endmodule

Sec_8/ForwardUnit.v

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ module ForwardUnit
2121
shouldForward1,
2222
shouldForward2,
2323
);
24-
24+
2525
// define input and output ports
2626
input WB_En1;
2727
input WB_En2;
28-
//input Is_Imm1;
29-
//input Is_Imm2;
3028
input Is_Imm;
3129
input mem_W_En;
3230
input [1:0] BR_Type;
@@ -54,7 +52,7 @@ module ForwardUnit
5452
reg [31:0] srcOut2;
5553
reg [31:0] memOut;
5654

57-
// define branch types
55+
// define branch types
5856
parameter NO_BRANCH_Code = 2'b0;
5957
parameter BEZ_Code = 2'b01;
6058
parameter BNE_Code = 2'b10;
@@ -90,7 +88,7 @@ module ForwardUnit
9088
begin
9189
srcOut2 <= aluResult2;
9290
end
93-
91+
9492
if (shouldForwardMemFromExe)
9593
memOut <= aluResult1;
9694
else
@@ -100,4 +98,3 @@ module ForwardUnit
10098
memOut <= readdata2;
10199
end
102100
endmodule
103-

Sec_8/ID_Reg.v

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module ID_Stage_reg
3636
EXE_Cmd,
3737
PC
3838
);
39-
39+
4040
// input and output ports
4141
input clk;
4242
input rst;
@@ -72,7 +72,7 @@ module ID_Stage_reg
7272
output [31:0] data1;
7373
output [31:0] data2;
7474
output [31:0] PC;
75-
75+
7676
// registers
7777
reg [1:0] BR_Type;
7878
reg [3:0] EXE_Cmd;
@@ -89,13 +89,13 @@ module ID_Stage_reg
8989
reg MEM_R_En;
9090
reg MEM_W_En;
9191
reg [31:0] PC;
92-
92+
9393
// build module
94-
94+
9595
// pass instruction decode outputs
9696
always @(posedge clk)
9797
begin
98-
if(rst | branch_taken | stall)
98+
if(rst | branch_taken)
9999
begin
100100
dest <= 5'b0;
101101
readdata1 <= 32'b0;
@@ -116,23 +116,26 @@ module ID_Stage_reg
116116
end
117117
else
118118
begin
119-
dest <= dest_in;
120-
readdata1 <= readdata1_in;
121-
readdata2 <= readdata2_in;
122-
Is_Imm <= Is_Imm_in;
123-
Immediate <= Immediate_in;
124-
data1 <= data1_in;
125-
data2 <= data2_in;
126-
WB_En <= WB_En_in;
127-
MEM_R_En <= MEM_R_En_in;
128-
MEM_W_En <= MEM_W_En_in;
129-
BR_Type <= BR_Type_in;
130-
EXE_Cmd <= EXE_Cmd_in;
131-
PC <= PC_in;
132-
src1 <= src1_in;
133-
src2 <= src2_in;
134-
dest <= dest_in;
119+
if (~stall)
120+
begin
121+
dest <= dest_in;
122+
readdata1 <= readdata1_in;
123+
readdata2 <= readdata2_in;
124+
Is_Imm <= Is_Imm_in;
125+
Immediate <= Immediate_in;
126+
data1 <= data1_in;
127+
data2 <= data2_in;
128+
WB_En <= WB_En_in;
129+
MEM_R_En <= MEM_R_En_in;
130+
MEM_W_En <= MEM_W_En_in;
131+
BR_Type <= BR_Type_in;
132+
EXE_Cmd <= EXE_Cmd_in;
133+
PC <= PC_in;
134+
src1 <= src1_in;
135+
src2 <= src2_in;
136+
dest <= dest_in;
137+
end
135138
end
136139
end
137-
140+
138141
endmodule

Sec_8/MEM_Reg.v

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module MEM_Stage_reg
33
(
44
clk,
55
rst,
6+
stall,
67
PC_in,
78
PC,
89
WB_En_in,
@@ -18,10 +19,11 @@ module MEM_Stage_reg
1819
ALU_result,
1920
Mem_Data
2021
);
21-
22+
2223
// input and output ports
2324
input clk;
2425
input rst;
26+
input stall;
2527
input WB_En_in;
2628
input MEM_R_En_in;
2729
input Is_Imm_in;
@@ -36,7 +38,7 @@ module MEM_Stage_reg
3638
output [31:0] PC;
3739
output [31:0] ALU_result;
3840
output [31:0] Mem_Data;
39-
41+
4042
// registers
4143
reg WB_En;
4244
reg MEM_R_En;
@@ -45,7 +47,7 @@ module MEM_Stage_reg
4547
reg [31:0] PC;
4648
reg [31:0] ALU_result;
4749
reg [31:0] Mem_Data;
48-
50+
4951
// build module
5052
always @(posedge clk)
5153
begin
@@ -61,14 +63,16 @@ module MEM_Stage_reg
6163
end
6264
else
6365
begin
64-
WB_En <= WB_En_in;
65-
MEM_R_En <= MEM_R_En_in;
66-
Is_Imm <= Is_Imm_in;
67-
dest <= dest_in;
68-
PC <= PC_in;
69-
ALU_result <= ALU_result_in;
70-
Mem_Data <= Mem_Data_in;
66+
if (~stall) begin
67+
WB_En <= WB_En_in;
68+
MEM_R_En <= MEM_R_En_in;
69+
Is_Imm <= Is_Imm_in;
70+
dest <= dest_in;
71+
PC <= PC_in;
72+
ALU_result <= ALU_result_in;
73+
Mem_Data <= Mem_Data_in;
74+
end
7175
end
7276
end
73-
77+
7478
endmodule

Sec_8/MIPS.v

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ module MIPS
1313
);
1414

1515
// input and outputs
16-
input clk;
17-
input rst;
18-
input Sel;
19-
output SRAMWEn;
20-
output SRAMOE;
16+
input clk;
17+
input rst;
18+
input Sel;
19+
output SRAMWEn;
20+
output SRAMOE;
2121
output [17:0] SRAMaddress;
22-
output [5:0] Instruction;
22+
output [5:0] Instruction;
2323
inout [15:0] SRAMdata;
2424

2525
// wires
@@ -237,6 +237,7 @@ module MIPS
237237
(
238238
.clk(clk),
239239
.rst(rst),
240+
.stall(Stall),
240241
.PC_in(PC2),
241242
.PC(PC3),
242243
.WB_En_in(WB_En22),
@@ -278,6 +279,7 @@ module MIPS
278279
(
279280
.clk(clk),
280281
.rst(rst),
282+
.stall(Stall),
281283
.PC_in(PC3),
282284
.PC(PC4),
283285
.WB_En_in(WB_En32),

Sec_8/SRAM_CTR.v

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module SRAM_CTR
3434
localparam READ_2 = 2;
3535
localparam WRITE_1 = 3;
3636
localparam WAIT = 4;
37-
37+
3838
// wire and registers
3939
reg SRAMWEn;
4040
reg SRAMOE;
@@ -47,11 +47,11 @@ module SRAM_CTR
4747
reg [2:0] nextState;
4848
reg [15:0] readData_L;
4949
reg [15:0] readData_H;
50-
50+
5151
// build module
5252
assign SRAM_NOT_READY = |counter | InnerStall;
5353
assign readData = { readData_H, readData_L };
54-
54+
5555
always @(posedge clk) begin
5656
if (rst)
5757
begin
@@ -85,7 +85,7 @@ module SRAM_CTR
8585
end
8686
end
8787
end
88-
88+
8989
// controller
9090
always @( posedge clk )
9191
begin
@@ -94,7 +94,7 @@ module SRAM_CTR
9494
else
9595
presentState <= nextState;
9696
end
97-
97+
9898
always @(*) begin
9999
case (presentState)
100100
INIT:
@@ -135,11 +135,10 @@ module SRAM_CTR
135135
end
136136
endcase
137137
end
138-
138+
139139
reg [15:0] data_to_sram;
140140
always @( * )
141141
begin
142-
data_to_sram = 0;
143142
case( presentState )
144143
INIT:
145144
begin
@@ -150,6 +149,7 @@ module SRAM_CTR
150149
InnerStall = 1'b1;
151150
SRAMWEn = 1'b1;
152151
SRAMOE = 1'b0;
152+
data_to_sram = 0;
153153
end
154154
else
155155
begin
@@ -165,6 +165,7 @@ module SRAM_CTR
165165
InnerStall = 1'b0;
166166
SRAMWEn = 1'b1;
167167
SRAMOE = 1'b1;
168+
data_to_sram = 0;
168169
end
169170
end
170171
end
@@ -174,13 +175,15 @@ module SRAM_CTR
174175
InnerStall = 1'b0;
175176
SRAMWEn = 1'b1;
176177
SRAMOE = 1'b0;
178+
data_to_sram = 0;
177179
end
178180
READ_2:
179181
begin
180182
SRAMaddress = { 1'b0, address, 1'b1 };
181183
InnerStall = 1'b0;
182184
SRAMWEn = 1'b1;
183185
SRAMOE = 1'b1;
186+
data_to_sram = 0;
184187
end
185188
WRITE_1:
186189
begin
@@ -196,11 +199,11 @@ module SRAM_CTR
196199
InnerStall = 1'b0;
197200
SRAMWEn = 1'b1;
198201
SRAMOE = 1'b1;
202+
data_to_sram = 0;
199203
end
200204
endcase
201205
end
202-
203-
assign SRAMdata = ((presentState == WRITE_1) || ((presentState == INIT) && (MEM_W_EN == 1))) ? data_to_sram : {16{1'bz}} ;
204-
205-
endmodule
206206

207+
assign SRAMdata = (~(|(presentState ^ WRITE_1)) || (~(|(presentState ^ INIT)) && (MEM_W_EN == 1))) ? data_to_sram : {16{1'bz}} ;
208+
209+
endmodule

0 commit comments

Comments
 (0)