Skip to content

Commit 7989a2d

Browse files
committed
Fix wrong input/output
1 parent 67c4297 commit 7989a2d

File tree

4 files changed

+61
-35
lines changed

4 files changed

+61
-35
lines changed

Sec_8/Hazard.v

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Hazard
1313
dest2,
1414
Stall
1515
);
16-
16+
1717
// define input and output ports
1818
input Sel;
1919
input WB_En1;
@@ -27,19 +27,34 @@ module Hazard
2727
input [4:0] dest2;
2828
output Stall;
2929

30-
// define branch types
30+
// wires and registers
31+
wire shouldForward1FromExe;
32+
wire shouldForward2FromExe;
33+
wire shouldForward1FromMem;
34+
wire shouldForward2FromMem;
35+
wire shouldForwardMemFromExe;
36+
wire shouldForwardMemFromMem;
37+
38+
// define branch types
3139
parameter NO_BRANCH_Code = 2'b0;
3240
parameter BEZ_Code = 2'b01;
3341
parameter BNE_Code = 2'b10;
3442
parameter JMP_Code = 2'b11;
35-
43+
44+
assign shouldForward1FromExe = !( src1 ^ dest1 ) & WB_En1 & |dest1;
45+
assign shouldForward2FromExe = !( src2 ^ dest1 ) & WB_En1 & (~Is_Imm | !(BR_Type ^ BNE_Code)) & |dest1;
46+
// assign shouldForwardMemFromExe = !( src2 ^ dest1 ) & WB_En1 & mem_W_En & |dest1;
47+
assign shouldForward1FromMem = ((!( src1 ^ dest2 )) & WB_En2) & (|dest2);
48+
assign shouldForward2FromMem = ((!( src2 ^ dest2 )) & WB_En2 & (~Is_Imm | !(BR_Type ^ BNE_Code))) & |dest2;
49+
// assign shouldForwardMemFromMem = !( src2 ^ dest2 ) & WB_En2 & mem_W_En & |dest2;
50+
assign shouldForward1 = shouldForward1FromExe | shouldForward1FromMem;
51+
assign shouldForward2 = shouldForward2FromExe | shouldForward2FromMem;
52+
3653
// build module
3754
assign Stall = (
38-
( ( |src1 & !( src1 ^ dest1 ) & WB_En1 ) |
39-
( |src2 & !( src2 ^ dest1 ) & WB_En1 & (~Is_Imm | !(BR_Type ^ BNE_Code) ) ) |
40-
( |src1 & !( src1 ^ dest2 ) & WB_En2 ) |
41-
( |src2 & !( src2 ^ dest2 ) & WB_En2 & (~Is_Imm | !(BR_Type ^ BNE_Code) ) ) ) &
42-
Sel
43-
) | SRAM_NOT_READY ;
44-
55+
shouldForward1 |
56+
shouldForward2 &
57+
Sel
58+
) | SRAM_NOT_READY ;
59+
4560
endmodule

Sec_8/MEM.v

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,18 @@ module MEM_Stage
6161
.address(realaddress),
6262
.readData(readData)
6363
);
64-
// assign readdata = (read) ? registers[realaddress[7:0]] : 32'b0;
64+
65+
// assign SRAM_NOT_READY = 1'b0;
66+
// assign readdata = (read) ? registers[realaddress[7:0]] : 32'b0;
6567
assign wbData = (read) ? readdata : aluResult;
68+
6669
// write part
67-
/* always @(posedge clk)
68-
begin
69-
if(write)
70-
begin
71-
registers[realaddress] <= writedata;
72-
end
73-
end */
70+
// always @(posedge clk)
71+
// begin
72+
// if(write)
73+
// begin
74+
// registers[realaddress] <= writedata;
75+
// end
76+
// end
7477

7578
endmodule

Sec_8/MIPS.v

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ module MIPS
66
rst,
77
Sel,
88
SRAMaddress, // SRAM Address bus 18 Bits
9-
SRAMWEn, // SRAM Write Enable
9+
SRAMWEn, // SRAM Write Enable
1010
SRAMOE, // SRAM Output Enable
1111
SRAMdata, // SRAM Data bus 16 Bits
1212
Instruction
1313
);
14-
14+
1515
// input and outputs
1616
input clk;
1717
input rst;
1818
input Sel;
19-
input SRAMWEn;
20-
input SRAMOE;
21-
input [17:0] SRAMaddress;
19+
output SRAMWEn;
20+
output SRAMOE;
21+
output [17:0] SRAMaddress;
2222
output [5:0] Instruction;
2323
inout [15:0] SRAMdata;
24-
24+
2525
// wires
2626
wire WB_En21;
2727
wire WB_En22;
@@ -86,12 +86,12 @@ module MIPS
8686
wire [31:0] ALU_Result42;
8787
wire [31:0] Mem_Data1;
8888
wire [31:0] Mem_Data2;
89-
89+
9090
// assemble modules
91-
91+
9292
// output
9393
assign Instruction = Instruction1[31:26];
94-
94+
9595
// instruction fetch
9696
IF_Stage IFS
9797
(
@@ -103,7 +103,7 @@ module MIPS
103103
.branch_taken(Branch_Taken),
104104
.PC(PC11)
105105
);
106-
106+
107107
// instruction fetch register
108108
IF_Stage_reg IFR
109109
(
@@ -116,7 +116,7 @@ module MIPS
116116
.Instruction(Instruction2),
117117
.PC(PC12)
118118
);
119-
119+
120120
// instruction decode
121121
ID_Stage IDS
122122
(
@@ -301,5 +301,5 @@ module MIPS
301301
.Mem_Data(Mem_Data2),
302302
.WB_Data(WB_Data)
303303
);
304-
304+
305305
endmodule

Sec_8/Test.v

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,28 @@ module test;
66
reg rst;
77
reg Sel;
88
wire [5:0] Instruction;
9-
9+
wire [17:0] SRAMaddress;
10+
wire SRAMWEn;
11+
wire SRAMOE;
12+
wire [15:0] SRAMdata;
13+
1014
// module under test
1115
MIPS UUT
1216
(
1317
clk,
1418
rst,
1519
Sel,
20+
SRAMaddress, // SRAM Address bus 18 Bits
21+
SRAMWEn, // SRAM Write Enable
22+
SRAMOE, // SRAM Output Enable
23+
SRAMdata, // SRAM Data bus 16 Bits
1624
Instruction
1725
);
18-
26+
1927
// write a test
20-
28+
2129
initial repeat (900) #(10) clk = ~clk;
22-
30+
2331
initial
2432
begin
2533
clk = 0; rst = 0; Sel = 0;
@@ -29,5 +37,5 @@ module test;
2937
#( 35 ) rst = 1;
3038
#( 40 ) rst = 0;
3139
end
32-
40+
3341
endmodule

0 commit comments

Comments
 (0)