Verilog $fseek未读取十六进制文件中的字节
我似乎无法读取十六进制文件中的第四个字节:Verilog $fseek未读取十六进制文件中的字节,verilog,system-verilog,Verilog,System Verilog,我似乎无法读取十六进制文件中的第四个字节: module file_read(); integer fd,file_char; logic [7:0] captured_data; initial begin fd = $fopen("README.lz4", "rb"); while (!$feof(fd)) begin file_char=$fseek(fd,5,0);
module file_read();
integer fd,file_char;
logic [7:0] captured_data;
initial begin
fd = $fopen("README.lz4", "rb");
while (!$feof(fd)) begin
file_char=$fseek(fd,5,0);
$display("file char is %h",file_char);
end
end
endmodule
文件内容是
00000000 04 22 4d 18 64 40 a7 43....
.........
$fseek不从文件中读取字符,它只指定从文件中读取字符的位置。相反,您可以使用$fgetc:
因此,我已将调用移到循环外的$fseek-我们只想在给定您所描述的格式的情况下执行一次。我还将偏移量更改为4,假设您想跳过00000000。我已将$fseek返回值分配给的变量更改为status,因为这是从$fseek返回的:
0表示成功,1表示错误
另外,$fgetc返回一个-1表示文件结束。因此,您可能希望将while循环更改为do while循环,并在最后测试file_char的值,并去掉$feof eg
这两个代码块我都没有测试过,因为没有可以测试它们的文件。是的,这就是为什么我要用十六进制读取文件。这不可能吗?@coding\u gal你应该可以点击文章下方的edit,这样你就可以编辑实际的文章来删除评论了。您还应该告诉我们运行程序时会发生什么。
module file_read();
integer fd,file_char,status;
logic [7:0] captured_data;
initial begin
fd = $fopen("README.lz4", "rb");
status=$fseek(fd,4,0);
while (!$feof(fd)) begin
file_char=$fgetc(fd);
$display("file char is %h",file_char);
end
end
endmodule
module file_read();
integer fd,file_char,status;
logic [7:0] captured_data;
initial begin
fd = $fopen("README.lz4", "rb");
status=$fseek(fd,4,0);
assert (status);
do begin
file_char=$fgetc(fd);
$display("file char is %h",file_char);
end
while (file_char != -1);
end
endmodule