卢骏 · 2020年05月22日

systemverilog使用$fwrite系统函数打印信息到屏幕

使用systemverilog(以下简称sv),除了使用$display系统函数,打印信息到屏幕上,还可以使用$fwrite系统函数,进行打印。

$fwrite的函数的第一个参数,是文件描述符。后续参数与$display系统函数参数一致。

在sv的标准中,有如下说明:

The file descriptor fd is a 32-bit packed array value. The MSB (bit 31) of a fd is reserved and shall always be set; this allows implementations of the file input and output functions to determine how the file was opened. The remaining bits hold a small number indicating what file is opened. Three file descriptors are pre-opened; they are STDIN, STDOUT, and STDERR, which have the values 32'h8000_0000, 32'h8000_0001, and 32'h8000_0002, respectively. STDIN is pre-opened for reading, and STDOUT and STDERR are pre-opened for append.

从该说明中,可以得到

文件描述符说明
0x8000_0000STDIN:标准输入
0x8000_0001STDOUT:标准输出
0x8000_0002STDERR:标准错误输出

因此,只需要执行

$fwrite(0x80000002, "hello world");

就可以向屏幕打印hello world。

更多相关阅读

原文首发于骏的世界博客
作者:卢骏.
更多IC设计相关的文章请关注IC设计极术专栏,每日更新。

推荐阅读
关注数
10974
内容数
1216
主要交流IC以及SoC设计流程相关的技术和知识
目录
极术微信服务号
关注极术微信号
实时接收点赞提醒和评论通知
安谋科技学堂公众号
关注安谋科技学堂
实时获取安谋科技及 Arm 教学资源
安谋科技招聘公众号
关注安谋科技招聘
实时获取安谋科技中国职位信息