在 example 下面,用于从带有systemverilog的二进制文件中读取 .
如IEEE SV标准文档中所示, "nchar_code" 将返回读取的字节数/字符数 . 如果在上次读取时已经达到EOF,则该数字将为零 . 请注意,“ nchar_code ”可以为零 but 尚未达到EOF,如果在数据文件的末尾有空格或返回,则会发生这种情况 .
您可以使用$ fread函数控制要读取的字节数 . 这是通过以下示例的"data_write_temp"或"mem"的 type definition 完成的 . 如果 "data_write_temp" 变量是16位长,那么每次调用$ fread时它将读取16位 . 此外,$ fread将返回"nchar_code=2",因为16位是2bytes . 如果"data_write_temp"是示例中的32位,则$ fread将读取nchar_code = 4bytes(32bits) . 您还可以定义一个数组,$ fread函数将尝试填充该数组 .
让我们定义一个多维数组 mem .
logic [31:0] mem [0:2][0:4][5:8];
在示例单词内容中, wzyx ,
-w shows the start of the word
-z corresponds to words of the [0:2] dimension (3 blocks).
-y corresponds to words of the [0:4] dimension (5 rows).
-x corresponds to words of the [5:8] dimension (4 columns).