-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMEM.v
75 lines (66 loc) · 1.26 KB
/
MEM.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
// build a module for instruction decode
module MEM_Stage
(
clk,
rst,
read,
write,
aluResult,
writedata,
SRAM_NOT_READY,
SRAMaddress,
SRAMWEn,
readdata,
wbData,
SRAMdata,
);
// input and outputs
input clk;
input rst;
input read;
input write;
output SRAMWEn;
input [31:0] aluResult;
input [31:0] writedata;
output [17:0] SRAMaddress;
output SRAM_NOT_READY;
output [31:0] readdata;
output [31:0] wbData;
inout [15:0] SRAMdata;
// registers and wires
reg [31:0] registers[255:0];
wire [15:0] realaddress;
// build module
// memory address generator
MemAdd MA
(
.address_in(aluResult[15:0]),
.address(realaddress)
);
// read part
// SRAM_CTR sram
// (
// .clk(clk),
// .MEM_R_EN(read),
// .MEM_W_EN(write),
// .rst(rst),
// .SRAMaddress(SRAMaddress),
// .SRAMWEn(SRAMWEn),
// .SRAMdata(SRAMdata),
// .SRAM_NOT_READY(SRAM_NOT_READY),
// .writeData(writedata),
// .address(realaddress),
// .readData(readdata)
// );
assign SRAM_NOT_READY = 1'b0;
assign readdata = (read) ? registers[realaddress[7:0]] : 32'b0;
assign wbData = (read) ? readdata : aluResult;
// write part
always @(posedge clk)
begin
if(write)
begin
registers[realaddress] <= writedata;
end
end
endmodule