标签:
1 Memories
Memories file format is shown below, the address is specified as @ <address> in hexadecimal.
@003
00000011
00000100
00000101
00000110
00000111
00001000
00001001
With the above file it can be seen if the memory is large it would become very tedious to work out the address of a specific byte, so it is normally a good idea to use milestones along the memory file, so a larger file may look something like the following:
@003
00000011
00000100
00000101
@006
00000110
00000111
@008
00001000
00001001
or if the data is contiguous, omit the address entirely.
2 Syntax:
$readmemb ("<file_name>", <memory_name>");
$readmemb ("<file_name>", <memory_name>, memory_start");
$readmemb ("<file_name>", <memory_name>, memory_start, memory_finish");
The memory_start and memory_finish are optional.
3 Example
Now that a memory file exists to access it, it has to be initialised for memory reading.
module testmemory; reg [7:0] memory [9:0]; integer index; initial
begin $readmemb("mem.dat", memory); for(index = 0; index < 10; index = index + 1) $display("memory[%d] = %b", index[4:0], memory[index]); end endmodule // testmemory
with the file mem.data as
1000_0001
1000_0010
0000_0000
0000_0001
0000_0010
0000_0011
0000_0100
0000_0101
0000_0110
0000_0000
标签:
原文地址:http://www.cnblogs.com/mengdie/p/4333169.html