forked from Wangxk226/ComputerSystem_Experiment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMEM.v
More file actions
65 lines (51 loc) · 1.45 KB
/
MEM.v
File metadata and controls
65 lines (51 loc) · 1.45 KB
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
`include "lib/defines.vh"
module MEM(
input wire clk,
input wire rst,
// input wire flush,
input wire [`StallBus-1:0] stall,
input wire [`EX_TO_MEM_WD-1:0] ex_to_mem_bus,
input wire [31:0] data_sram_rdata,
output wire [`MEM_TO_WB_WD-1:0] mem_to_wb_bus
);
reg [`EX_TO_MEM_WD-1:0] ex_to_mem_bus_r;
always @ (posedge clk) begin
if (rst) begin
ex_to_mem_bus_r <= `EX_TO_MEM_WD'b0;
end
// else if (flush) begin
// ex_to_mem_bus_r <= `EX_TO_MEM_WD'b0;
// end
else if (stall[3]==`Stop && stall[4]==`NoStop) begin
ex_to_mem_bus_r <= `EX_TO_MEM_WD'b0;
end
else if (stall[3]==`NoStop) begin
ex_to_mem_bus_r <= ex_to_mem_bus;
end
end
wire [31:0] mem_pc;
wire data_ram_en;
wire [3:0] data_ram_wen;
wire sel_rf_res;
wire rf_we;
wire [4:0] rf_waddr;
wire [31:0] rf_wdata;
wire [31:0] ex_result;
wire [31:0] mem_result;
assign {
mem_pc, // 75:44
data_ram_en, // 43
data_ram_wen, // 42:39
sel_rf_res, // 38
rf_we, // 37
rf_waddr, // 36:32
ex_result // 31:0
} = ex_to_mem_bus_r;
assign rf_wdata = sel_rf_res ? mem_result : ex_result;
assign mem_to_wb_bus = {
mem_pc, // 69:38
rf_we, // 37
rf_waddr, // 36:32
rf_wdata // 31:0
};
endmodule