-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrom_memory.v
36 lines (32 loc) · 846 Bytes
/
rom_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
```verilog
module rom_memory #(
parameter ADDR_WIDTH = 8,
parameter DATA_WIDTH = 32,
parameter DEPTH = 256 // 2^8
)(
input wire clk,
input wire [ADDR_WIDTH-1:0] addr,
input wire enable,
output reg [DATA_WIDTH-1:0] data_out
);
// ROM storage
reg [DATA_WIDTH-1:0] rom_array [0:DEPTH-1];
// Initialize ROM with some data
initial begin
// Example initialization
rom_array[0] = 32'hDEADBEEF;
rom_array[1] = 32'h12345678;
rom_array[2] = 32'hABCDEF01;
// ... add more initializations as needed
end
// Read operation
always @(posedge clk) begin
if (enable) begin
data_out <= rom_array[addr];
end
else begin
data_out <= {DATA_WIDTH{1'bz}}; // High impedance when disabled
end
end
endmodule
```