systemverilog文件操作

时间:2019-10-27 18:20:59   收藏:0   阅读:1433

1. fopen

string file_name;

int file_handle;

initial begin

   file_handle = $fopen(file_name,"r"); //只读方式打开;

   while(!$feof(file_handle))

        $fscanf(file_handle,"%s %d",s, i); //获得数据;

end

2. readmemh/readmemb tasks,由于memory文件中只能有数字,空格和注释,所以一般用在读取纯数字文件;

$readmemb ( " file_name " , memory_name [ , start_addr [ , finish_addr ] ] ) ; //binary
$readmemh ( " file_name " , memory_name [ , start_addr [ , finish_addr ] ] ) ; //16进制

For example:
reg [7:0] mem[1:256];
Given this declaration, each of the following statements load data into mem in a different manner:
initial $readmemh("mem.data", mem);
initial $readmemh("mem.data", mem, 16);
initial $readmemh("mem.data", mem, 128, 1);
The first statement loads up the memory at simulation time 0 starting at the memory address 1. The second
statement begins loading at address 16 and continue on toward address 256. For the third and final
statement, loading begins at address 128 and continue down toward address 1.

原文:https://www.cnblogs.com/lybinger/p/11748109.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!