$ readmemh $ writememh相关资源 [英] $readmemh $writememh related resources
问题描述
突然,我被迫研究一些使用$ readmemh和$ writememh的verilog测试平台代码.我了解它基本上是读到内存和写到内存.如果您能指出与这些例程相关的一些资源,我将非常高兴. PS:我在Google上搜索没有成功. (我对Verilog来说非常新...
我同意找到有关readmem/writemem的内容并不容易.您可以在这里找到一些: https://www.fullchipdesign.com/readmemh.htm
无论如何,关于这些功能没有太多要说的,语法是:
$readmem[hb]("File", ArrayName, StartAddr, EndAddr)
$writemem[hb]("File", ArrayName, StartAddr, EndAddr)
Verilog对文件格式非常挑剔,文本文件中的位数必须与数组中的位数匹配.
我建议您通过定义一个数组来进行一些操作,用数据填充它,然后用writememh/writememb将其写出,然后打印出来.
这样的事情应该会让您入门(不要尝试!).
integer i;
reg [7:0] memory [0:15]; // 8 bit memory with 16 entries
initial begin
for (i=0; i<16; i++) begin
memory[i] = i;
end
$writememb("memory_binary.txt", memory);
$writememh("memory_hex.txt", memory);
end
干杯!
Suddenly, I am made to look into some verilog testbench code which heavily uses $readmemh, and $writememh. I understood that it basically read to memory and write to memory. I will be happy if you can point to some resources related to those routines. PS: I searched in google for no success. (I am very ... very new to Verilog)
I agree its not too easy to find something about readmem/writemem. You can find a little bit here: https://www.fullchipdesign.com/readmemh.htm
Anyway there is not too much to say about these functions, the syntax is:
$readmem[hb]("File", ArrayName, StartAddr, EndAddr)
$writemem[hb]("File", ArrayName, StartAddr, EndAddr)
Verilog is very picky about the file format, the number of bit in the text file have to match the number of bits in the array.
I recommend you play around a little bit by defining an array, filling it up with data write it out with writememh/writememb and print it out afterwards.
Something like this should get you started (not tried out!).
integer i;
reg [7:0] memory [0:15]; // 8 bit memory with 16 entries
initial begin
for (i=0; i<16; i++) begin
memory[i] = i;
end
$writememb("memory_binary.txt", memory);
$writememh("memory_hex.txt", memory);
end
Cheers!
这篇关于$ readmemh $ writememh相关资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!