weiqi7777

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

0
阅读(3542)

使用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_0000

STDIN:标准输入

0x8000_0001

STDOUT:标准输出

0x8000_0002

STDERR:标准错误输出

因此,只需要执行

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

就可以向屏幕打印hello world。