$readmemh $writememh related resources

依然范特西╮ 提交于 2019-12-20 12:23:33

问题


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)


回答1:


I agree its not too easy to find something about readmem/writemem. You can find a little bit here: http://fullchipdesign.com/index_files/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;
    end
    $writememb("memory_binary.txt", memory);
    $writememh("memory_hex.txt", memory);
end

Cheers!




回答2:


Reading HEX file would work like this:

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;
    end
    $readmemh("memory_binary.txt", memory);

end


来源:https://stackoverflow.com/questions/628603/readmemh-writememh-related-resources

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!