Verilog中$readmemh和$writememh的作用是什么? [英] What is the function of $readmemh and $writememh in Verilog?

查看:125
本文介绍了Verilog中$readmemh和$writememh的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在查看一些大量使用 $readmemh$writememh 的 Verilog 测试平台代码.

I have been looking at some Verilog testbench code that heavily uses $readmemh and $writememh.

我有一个模糊的理解,这些函数基本上是从内存读取和写入.它们的具体功能是什么?它们是如何工作的?

I have a vague understanding that these functions basically read to and write from memory. What is their specific function and how do they work?

推荐答案

我同意要找到关于 readmem/writemem 的东西并不容易.你可以在这里找到一点:https://www.fullchipdesign.com/readmemh.htm

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 对文件格式非常挑剔,文本文件中的位数必须与数组中的位数相匹配.

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.

我建议你定义一个数组,用数据填充它,用 writememh/writememb 将它写出来,然后打印出来.

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

这篇关于Verilog中$readmemh和$writememh的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆