Verilog中的关于文件操作的函数和任务

来源:互联网 发布:springboot源码分析 编辑:程序博客网 时间:2024/05/24 06:51
 Verilog中的关于文件操作的函数和任务
2012-09-03 21:32:14
标签:verilog $fdisplay $fwrite
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://lihaichuan.blog.51cto.com/498079/981084
$fopen(“filename”) 打开文件
$fdisplay(handle1,p1,p2, …pn) 写文件
$fclose(handle1) 关闭文件
1、打开文件
任务$fopen(“filename”)返回值为一个被称为多通道描述符的32位值,多通道描述符只有一位被设置成1。标准输出通道符其最低位设置成1,其余位为0,即00000000000000000000000000000001 ,即通道0用于在命令框中或者仿真软件中进行输出
标准输出一直是开放的。以后调用$fopen的每一次都打开一个新的通道,并且依次返回第1位、第2为等(有第0位)直到第30位,第31位保留,依次称为通道1,通道2等。
通道号与多通道符中被设置为1的位相对应。
如果不存在打开的文件,就会创建此文件。
如:
Integer handle1,handle2,handle3;
Initial begin
       handle1=$fopen(“file1.txt”); //handle1的值为00000000000000000000000000000010
handle2=$fopen(“file2.txt”); //handle2的值为00000000000000000000000000000100
handle3=$fopen(“file3.txt”); //handle3的值为00000000000000000000000000001000
end
多通道描述符的优点可以有选择的同时写多个文件
 
2、写文件
系统任务 $fdisplay $fmonitor $fwrite $fstobe 都用于写文件。这些任务与常规系统任务$display $monitor 等类似,但是它们提供了写文件功能。
如:
Integer handle1,handle2,handle3;
Integer desc1,desc2,desc3;
Initial begin
handle1=$fopen(“file1.txt”); //handle1的值为00000000000000000000000000000010
handle2=$fopen(“file2.txt”); //handle2的值为00000000000000000000000000000100
handle3=$fopen(“file3.txt”); //handle3的值为00000000000000000000000000001000
      
      
 
       desc1=handle1 | 1; //按位或,desc1=32’h0000_0003
       $fdisplay(desc1,”handle1 ”);//将字符串 handle1写到file1.txt和标准输出中。
desc2=handle2 | handle 1; //按位或,desc1=32’h0000_0006
       $fdisplay(desc1,”handle1 ”);//将字符串 handle1写到file1.txt和file1.txt中。
      
       desc3=handle3;
       $fdisplay(handle3,”handle1”);//将字符串 handle1写到file3.txt中。
end
3、关闭文件
如: $fclose(handle1); 文件一旦关闭就不能写入。
 
 

本文出自 “李海川” 博客,请务必保留此出处http://lihaichuan.blog.51cto.com/498079/981084


0 0