繁体   English   中英

使用SystemVerilog读取文件中的可变长度字符串

[英]Read Variable length string in a file using SystemVerilog

假设我有可变长度的字符串,如下所示:

Write <Address> <Data0> <Data1> <Data2>
Read <Address>
Write <Address> <Data0>
Write <Address> <Data0> <Data1> <Data2> <Data3>

如何使用文件操作在SystemVerilog或Verilog中阅读。 当文本长度固定时,我会阅读

integer file    = $fopen(file_name,"r");
code = $fgets(line, file);
code = $sscanf(line, "%s %h %h %h", txn_type, Address, Data[i]);

只要字段数量不固定,就可以使用$sscanf ,只要您提供最大数量的字段即可。 放置在code的返回值指示扫描的参数的实际数量。 因此,只需创建一个虚拟参数列表并复制该行提供的参数即可

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM