-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_memory.v
49 lines (38 loc) · 1.06 KB
/
data_memory.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
module DataMemory(address, write_data, MemRead, MemWrite, clk, read_data);
input [31:0] address, write_data;
input MemRead, MemWrite, clk;
output wire [31:0] read_data;
reg [7:0] mem [0:4096];
assign #200 read_data = (MemRead)? {mem[address], mem[address + 1], mem[address + 2], mem[address + 3]} : 32'bz;
always @ (posedge clk) begin
if(MemWrite)
#100 {mem[address], mem[address + 1], mem[address + 2], mem[address + 3]}= write_data;
end
initial begin
$readmemb("data-memory.mem", mem);
end
endmodule
module DataMemory_testbench();
reg [31:0] address, write_data;
reg MemRead, MemWrite, clk;
reg MemDataSign;
reg [1:0] MemDataSize;
wire [31:0] read_data;
DataMemory mem(address, write_data, MemRead, MemWrite, MemDataSize, MemDataSign, clk, read_data);
initial begin
clk = 0;
forever #500 clk = ~clk;
end
integer i;
initial begin
address = 16;
MemRead = 1;
MemWrite = 0;
#200
MemWrite = 1;
MemRead = 1;
address <= 4;
write_data <= 32'h01234567;
#200 $finish;
end
endmodule