一. open,close, write
fwrite(fd, data);
int fd;
fd = $fopen("file", "w”);
$fdisplay(fd,"%x", data);
$fclose(fd);
二. 判断文件是否存在
如果文件open 为0,代表打开失败,否则成功
三. 读取文件
fd = fopen("file", "r");
if (fd) begin // read successfule
while($feof(fd)) begin
$fgets(str, fd);
$display("%0s", str);
end
end
$fclose(fd);
or $fscanf(fd, "%s=%d", var, val); // return the number of match
如果同一个环境中有写有读,可能读出来是空的,那是因为前面的写没有真正的写到file中,可以使用$fflush(fd)
http://www.asic.co.in/Index_files/verilog_files/File_IO.htm