-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_array.v
More file actions
49 lines (35 loc) · 1.13 KB
/
Copy pathdata_array.v
File metadata and controls
49 lines (35 loc) · 1.13 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
`timescale 1ns / 1ps
module data_array #(
parameter DATA_WIDTH = 32,
parameter INDEX_WIDTH = 4,
parameter NUM_LINES = 16
)(
input clk,
input rst,
// Write Interface
input write_en,
input [INDEX_WIDTH-1:0] index,
input [DATA_WIDTH-1:0] data_in,
// Read Interface
output [DATA_WIDTH-1:0] data_out
);
// Data Memory
reg [DATA_WIDTH-1:0] data_mem [0:NUM_LINES-1];
integer i;
//----------------------------------------------------------
// Reset and Write Logic
//----------------------------------------------------------
always @(posedge clk) begin
if (rst) begin
for(i = 0; i < NUM_LINES; i = i + 1)
data_mem[i] <= {DATA_WIDTH{1'b0}};
end
else if(write_en) begin
data_mem[index] <= data_in;
end
end
//----------------------------------------------------------
// Read Logic (Combinational)
//----------------------------------------------------------
assign data_out = data_mem[index];
endmodule