C语言 Verilog 中的 $display 和 C 中的 printf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20803872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:33:23  来源:igfitidea点击:

$display in Verilog and printf in C

cverilog

提问by Tuyen Khuc

As you know in Veriloghas $display,$strobeand $monitor those used to display text on the screen. And in C has printfto display text on screen also.

如您所知,Veriloghas$display,$strobe和 $monitor 用于在屏幕上显示文本。在 C 中也printf必须在屏幕上显示文本。

My question is how can I use one of them ($display,$strobe,$monitor) like printfin C?

我的问题是如何使用其中之一 ( $display,$strobe,$monitor) 像printfin C

a: $display
b:$strobe
c:$monitor
d: all of them
e: other

回答by LuisEspinoza

$display("<format>", exp1, exp2, ...);  // formatted write to display
format indication %b %B binary
                  %c %C character (low 8 bits)
                  %d %D decimal  %0d for minimum width field
                  %e %E E format floating point %15.7E
                  %f %F F format floating point %9.7F
                  %g %G G general format floating point
                  %h %H hexadecimal
                  %l %L library binding information
                  %m %M hierarchical name, no expression
                  %o %O octal
                  %s %S string, 8 bits per character, 2′h00 does not print
                  %t %T simulation time, expression is  $time
                  %u %U unformatted two value data  0 and 1 
                  %v %V net signal strength
                %z %Z unformatted four value data  0, 1, x, z

escape sequences, quoted characters in strings \n   newline
                                               \t   tab
                                               \   backslash
                                               \"   quote
                                               \ddd octal
                                               %%   percent

any other characters between the quotes are displayed
the expressions are taken in order of the format indication
,, in the expression list inserts one space in the output