Read Only Memory(ROM): An Overview
Read-only memory widely known as ROM is a non-volatile memory that is used to store data or programs that do not change over time. As the name suggests, data can only be read from the memory. In digital design, ROM can be used to store image data or signal data for processing.
Memory File
A memory file is a simple file with an extension of *.mem that can store data in decimal, binary, or hexadecimal format. An example of a seven-segment ROM file is shown below:
0111111 // 0
0000110 // 1
1011011 // 2
1001111 // 3
1100110 // 4
1101101 // 5
1111101 // 6
0000111 // 7
1111111 // 8
1101111 // 9
Verilog Code
module rom #(parameter N = 7)(/*AUTOARG*/
// Outputs
data,
// Inputs
addr, en
);
// output
output [N-1:0] data;
//input
input [$clog2(N):0] addr;
input en;
/*AUTOREG*/
/*AUTOWIRE*/
reg [N-1:0] mem [0:9];
initial
begin
$display("-------- Loading ROM --------");
$readmemb("memory.mem", mem);
end
assign data = (en && (addr <= 'h9)) ? mem[addr] : 'h0;
endmodule