当前位置:网站首页>System tasks (display / print class) in Verilog - $display, $write, $strobe, $monitor
System tasks (display / print class) in Verilog - $display, $write, $strobe, $monitor
2022-06-26 13:03:00 【Lonely single blade】
summary
During verification and debugging , Sometimes it is very helpful to print some information on the terminal .
For example, you are verifying the loopback module of a serial port , The sender will send... At regular intervals 1 individual BYTE Data to the receiving end . If you don't want to verify whether the sending and receiving are consistent by comparing the waveforms one by one , You can choose to print each sent value and received value directly to the terminal .
Another example is your RTL A parameter in the has a value that is not within the expected range , You can print an error message to the terminal at this time , In this way, we can know RTL Is there a problem , Instead of staring at your oscillogram all the time .
Verilog Grammar provides us with 4 System functions , Variable information can be displayed on the terminal , According to its use method, it can be divided into 3 class :
- $display, $write
- $strobe
- $monitor
$display and $write
$display You can print a text message directly , And every time $display Post implementation meeting Word wrap , such as :
`timescale 1ns/1ns
module test_tb();
initial begin
$display("China NO1!");
$display("USA NO2!");
end
endmodule
stay vivado Print result of window observation :
$write The usage and $display Agreement , The difference lies in , One $write After statement execution , No line wrapping . Consider the following code :
`timescale 1ns/1ns
module test_tb();
initial begin
$write("China NO1!");
$write("USA NO2!");
end
endmodule
The print result is :
These two system functions can print text directly , You can also print the values of variables , The format for ( With $display For example ):
$display("%b %b",a,b) ;
and C The language is the same , among a,b Is the variable value of the expected output ,%b Format for variable output , It is expressed as 2 Binary output . Other output formats are as follows :
%h or %H | Hex format output | %c or %C | ASCII Code format output |
%d or %D | Decimal format output | %e or %E | Output in exponential format |
%o or %O | Output in octal format | %f or %F | Floating point numbers (real type ) Format output |
%b or %B | Binary format output | %t or %T | Current time format output |
%s or %S | String format output | %m or %M | Current hierarchy access path output |
In addition to this , Use escape characters , for example :
\n | A newline | %% | Percent sign "%" |
\t | tabs (Tab key ) | \0 | Octal characters |
\\ | The backslash "\" operator | \0x | Hexadecimal characters |
\" | Double quotes |
such as , Output 2 The process and result of adding numbers :
`timescale 1ns/1ns
module test_tb();
reg a;
reg b;
reg [1:0]sum;
initial begin
a = 0;
b = 0;
sum = a + b;
$display("%b + %b = %b",a,b,sum);
#10
a = 1;
b = 1;
sum = a + b;
$display("%b + %b = %b",a,b,sum);
end
endmodule
The printed results are displayed twice 1bit Binary addition process and result of :
$strobe
$strobe Show tasks for gating .$strobe Usage and $display Agreement , But the time it takes to print the message is $display There are differences ( You can also print text directly ).
When many sentences are related to $display When a task is executed at the same time , These statements and $display The execution order of is uncertain , Generally, it is executed according to the sequence structure of the program . The difference between the two is :$strobe The command will be completed at the end of the current time ; and $display Yes, as long as the emulator sees it, it will execute immediately .
$strobe It is in the After his statement is executed , To execute the display task . for example :
`timescale 1ns/1ns
module test_tb();
reg [3:0] a ;
initial begin
$strobe("begin!");
a = 1 ;
#1 ;
a <= a + 1 ;
// For the first time
$display("$display excuting result: %d.", a);
$strobe("$strobe excuting result: %d.", a);
#1 ;
$display();
// The second time it shows
$display("$display excuting result: %d.", a);
$strobe("$strobe excuting result: %d.", a);
$strobe("end!");
end
endmodule
The printing results are as follows :
You can see ,$strobe And $display The print content of is not consistent .
This is because the statement : a <= a + 1 ; in other words a The second assignment of is a non blocking assignment , Non blocking assignment takes time .
- When printing for the first time ,$display I won't care about you a Block assignment or non block assignment , It just prints a The current value 1. and $strobe Will wait until the non blocking assignment is completed before printing , So the printed value is 2.
- At the second printing , It's delayed again 1ns, So the non blocking assignment is completed , that $strobe And $display The printed contents of all are 2 了 .
therefore $strobe This system task is usually used to print the variable value of the current non blocking assignment .
$monitor
$monitor For monitoring tasks , For continuous monitoring of variables . As long as the variable changes ,$monitor The corresponding information will be printed and displayed . How to use it and $display Agreement .
The following code uses $monitor To monitor a,b,c this 3 A variable , As long as one of them changes , Will immediately print on the terminal .
`timescale 1ns/1ns
module test_tb();
reg [1:0] a ;
reg [1:0] b ;
reg [1:0] c ;
initial begin
a = 0 ;
b = 0 ;
c = 0 ;
$monitor("a=%d b=%d c=%d",a,b,c);
#50 $finish; //50ns Stop after
end
always #10 begin // Every time 10ns, Random generation a,b,c
a = {$random}%4;
b = {$random}%4;
c = {$random}%4;
end
endmodule
The terminal print results are as follows :
边栏推荐
- 软件测试测试常见分类有哪些?
- Detailed explanation of C const: definition and use of C constant
- 美学心得(第二百三十八集) 罗国正
- Mongodb of NoSQL - 03 mongodb CRUD
- 第01章_Linux下MySQL的安装与使用
- Redis learning - 05 node JS client operation redis and pipeline pipeline
- Source code learning: atomicinteger class code internal logic
- 使用SSH密钥对登陆服务器
- Record a phpcms9.6.3 vulnerability to use the getshell to the intranet domain control
- PostGIS calculation angle
猜你喜欢
[esp32-c3][rt-thread] run RT-Thread BSP minimum system based on esp32c3
Openlayers drawing dynamic migration lines and curves
Power Designer - Custom Comment button
Solution of Splunk iowait alarm
National standard gb28181 protocol easygbs video platform TCP active mode streaming exception repair
NoSQL mongodb - 02 mongodb server installation, mongodb shell, basic concepts and visualization tools
Stream流学习记录
Software testing - concept
倍福PLC实现绝对值编码器原点断电保持---bias的使用
.NET MAUI 性能提升
随机推荐
【Spark】.scala文件在IDEA中几种图标的解释
EasyGBS如何解决对讲功能使用异常?
倍福CX5130换卡对已有的授权文件转移操作
Splunk iowait 报警的解决
National standard gb28181 protocol easygbs video platform TCP active mode streaming exception repair
详细讲解C语言10(C语言系列)
processsing 函数random
File remote synchronization and backup artifact Rsync
软件测试 - 概念篇
opencv高速下载
黑马笔记---常用API
goto语句实现关机小程序
Record a phpcms9.6.3 vulnerability to use the getshell to the intranet domain control
记一次phpcms9.6.3漏洞利用getshell到内网域控
A must for programmers, an artifact utools that can improve your work efficiency n times
Redis learning - 06 drifting bottle case
倍福将EtherCAT模块分到多个同步单元运行--Sync Units的使用
5+API,清除应用缓存
Redis learning - 02 common data types, operation commands and expiration time
倍福TwinCAT通过Emergency Scan快速检测物理连接和EtherCAT网络