.verilog系统任务读写文件$fopen和$fdisplay的使用
来源:互联网 发布:java 获取对象类型 编辑:程序博客网 时间:2024/05/18 18:16
1.$fopen打开文件
用法1.$fopen("<文件名>");
用法2.<文件句柄>=$fopen("<文件名>");
注意:用$fopen打开文件会将原来的文件清空,若要读数据就用$readmemb,$readmemh就可以了,这个语句不会清空原来文件中的数据。
用$fopen的情况是为了取得句柄,即文件地址,也就是写文件时用$fdisplay(desc,"display1");时才用。
用法1自然无须多解释,对于用法2,句柄就是任务$fopen返回的多通道描述符,默认为32位,最低位(第0位)默认被设置1,默认开放标准输出通道,即transcript窗口。
module disp;
integer handle1,handle2,handle3;
integer handle1,handle2,handle3;
initial
begin
handle1=$fopen("file1.dat");
handle2=$fopen("file2.dat");
handle3=$fopen("file3.dat");
begin
handle1=$fopen("file1.dat");
handle2=$fopen("file2.dat");
handle3=$fopen("file3.dat");
$display("%h %h %h",handle1,handle2,handle3);
end
endmodule
输出
handle1=32‘h0000_0002
handle2=32'h0000_0004
handle3=32'h0000_0008
即对每一次使用$fopen函数后都打开了一个新的通道,并且返回了一个设置为1的位相对应。默认应该是0001,以上每调用分别设置为0010 ,0100,1000(只考虑最低四位)。
这个句柄对我们非常有用,因为在写文件时会用到。
2.写文件我们用到系统任务$fdisplay,$fwrite.
两者用法相似,前者写完就会自动换行,后者不会换行。
用法:$fdisplay(<文件描述符(句柄,用于确定是写哪一个文件)>,p1,p2(写入内容));
描述符是很有意思的(默认为32位),如上我们知道,文件句柄最多只能有一个1,但是描述符可以是有多个1,哪一个位上有1,就同时在这些位对应的输出文件上写文件。因此可以同时写多个文件。
只考虑后四位情况:
1,0001时,只进行在transcript对话框中的输出,
2,0101时,即对file2文件写又在transcript框输出、
3,1111时,对全部文件写,同时在transcript框输出。
由于每个句柄只有一个位置上是1,因此我们想在哪些文件中同时输出我们就可以用以下语句来写
desc=handleI | handleK | handleM | handleN | 1(一般与1或,最低位置1再transcript框输出。)
一个例子如下:
module disp;
integer handle1,handle2,handle3;
integer desc1,desc2,desc3;
initial
begin
handle1=$fopen("file1.dat");
handle2=$fopen("file2.dat");
handle3=$fopen("file3.dat");
$display("%h %h %h",handle1,handle2,handle3);
desc1=handle1|1;
$fwrite(desc1,"display 1");
$fmoniter(desc1,"display 1");
$fstrobe(desc1,"display 1");
desc2=handle2|handle1|1;
$fdisplay(desc2,"display 2");
desc3=handle3|1;
$fdisplay(32'd15,"display 3");
end
endmodule
integer handle1,handle2,handle3;
integer desc1,desc2,desc3;
initial
begin
handle1=$fopen("file1.dat");
handle2=$fopen("file2.dat");
handle3=$fopen("file3.dat");
$display("%h %h %h",handle1,handle2,handle3);
desc1=handle1|1;
$fwrite(desc1,"display 1");
$fmoniter(desc1,"display 1");
$fstrobe(desc1,"display 1");
desc2=handle2|handle1|1;
$fdisplay(desc2,"display 2");
desc3=handle3|1;
$fdisplay(32'd15,"display 3");
end
endmodule
- .verilog系统任务读写文件$fopen和$fdisplay的使用
- Verilog中$fopen $fdisplay $fclose的用法
- verilog系统任务对文件的读写操作
- c语言读写文件fopen和fopen
- Verilog中的关于文件操作的函数和任务
- JNI中新建文件、读写普通文件和驱动文件的方法综述fopen/open/creat/
- fopen读写文件
- fopen文件读写函数
- 文件读写fopen()
- Verilog 中与文件操作相关的系统任务与系统函数
- verilog读写文件测试
- verilog文件读写
- Verilog读写文件
- 使用c语言风格的文件读写fopen,在build gcce时会出现undefined reference错误
- Verilog HDL的任务和函数
- Verilog HDL的任务和函数
- 在Visual C++中使用fopen()函数来读写文件
- 在Visual C++中使用fopen()函数来读写文件
- 【thinkphp3.x】thinkphp3.x中cookie方法的使用
- AbisPlat框架整合Grid++Report报表
- IO操作 创建一个文件并写入一些文字数据
- 使用Junit4遇到Unrooted Tests错误
- MONOWALL 安装教程
- .verilog系统任务读写文件$fopen和$fdisplay的使用
- 系统任务$monitor 使用体会
- IO口的工作原理
- 论c++构造函数中的不合理设计
- unix网络编程 chapter4.11代码改写
- Delphi 在dbgrideh中表格输入数据时有效性的检查(转)
- 爱在西元前--程序员版
- IO操作 IO异常处理
- 编程之美-2.2-不要被阶乘吓倒