-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataMemory.v
45 lines (37 loc) · 896 Bytes
/
DataMemory.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
`timescale 1ns / 1ps
module DataMemory
(
input clk,
input MemRead,
input MemWrite,
input [31:0] address,
input [31:0] writeData,
output reg [31:0]readData
);
reg [7:0] datamemory [1023:0];
integer i;
initial begin
for(i=0;i<1024 ;i=i+1)begin
datamemory[i]=i;
end
end
always @ (posedge clk) begin
if (MemRead === 1) begin
readData <= {
datamemory[address+3],
datamemory[address+2],
datamemory[address+1],
datamemory[address]
};
end
if (MemWrite === 1) begin
datamemory[address] <= writeData[7:0];
datamemory[address+1] <= writeData[15:8];
datamemory[address+2] <= writeData[23:16];
datamemory[address+3] <= writeData[31:24];
end
if(MemRead === 1 && MemWrite === 1) begin
$display("Error : MemRead and MemWrite are 1 simultaneously!");
end
end
endmodule