systemverilog文件操作


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.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM