-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_memory.v
More file actions
executable file
·51 lines (45 loc) · 1.24 KB
/
data_memory.v
File metadata and controls
executable file
·51 lines (45 loc) · 1.24 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
module Data_Memory(
input clk,
// address input, shared by read and write port
input [7:0] mem_access_addr,
// write port
input [7:0] mem_write_data,
input mem_write_en,
input mem_read,
// read port
output [7:0] mem_read_data
);
reg [8 - 1:0] memory [8 - 1:0];
integer f,f1;
wire [2:0] ram_addr=mem_access_addr[2:0];
initial
begin
$readmemb("./test.data", memory,0,7);
f = $fopen("memory.dat");
$fdisplay(f,"time = %d\n", $time,
"\tmemory[0] = %b\n", memory[0],
"\tmemory[1] = %b\n", memory[1],
"\tmemory[2] = %b\n", memory[2],
"\tmemory[3] = %b\n", memory[3],
"\tmemory[4] = %b\n", memory[4],
"\tmemory[5] = %b\n", memory[5],
"\tmemory[6] = %b\n", memory[6],
"\tmemory[7] = %b\n", memory[7]);
#50
$fdisplay(f,"time = %d\n", $time,
"\tmemory[0] = %b\n", memory[0],
"\tmemory[1] = %b\n", memory[1],
"\tmemory[2] = %b\n", memory[2],
"\tmemory[3] = %b\n", memory[3],
"\tmemory[4] = %b\n", memory[4],
"\tmemory[5] = %b\n", memory[5],
"\tmemory[6] = %b\n", memory[6],
"\tmemory[7] = %b\n", memory[7]);
$fclose(f);
end
always @(posedge clk) begin
if (mem_write_en)
memory[ram_addr] <= mem_write_data;
end
assign mem_read_data = (mem_read==1'b1) ? memory[ram_addr]: 8'd0;
endmodule