文章目錄
-
- 前言
- 正文
-
- Display/Write Tasks
- Verilog Strobes
- Verilog Continuous Monitors
- Verilog Format Specifiers
- Verilog Escape Sequences
- 往期回顧
- 參考資料及推薦關注
顯示系統任務主要用于顯示資訊和調試資訊,從日志檔案中跟蹤仿真的流程,也有助于更快地進行調試。顯示任務有不同的組别和格式,它們可以列印數值。
仿真可不是隻有波形就完事無憂的,有的時候需要一些顯示任務将某些節點的資料列印出來,有利于分析。
如下格式語句一定見過吧:
$monitor ("[$monitor] time=%0t a=0x%0h b=0x%0h", $time, a, b);
$display ("[$display] time=%0t a=0x%0h b=0x%0h", $time, a, b);
類似的東西都很常見,這裡一起學習下吧。
$display
和
$write
都會按照參數清單中的順序顯示參數。
$display(<list_of_arguments>);
$write(<list_of_arguments>);
$write
不會在字元串末尾添加換行符,而
$display
會,從下面的例子可以看出。
module tb;
initial begin
$display ("This ends with a new line ");
$write ("This does not,");
$write ("like this. To start new line, use newline char
");
$display ("This always start on a new line !");
end
endmodule
This ends with a new line
This does not,like this. To start new line, use newline char
Hi there !
s t r o b e 在 當 前 d e l t a 時 間 步 長 結 束 時 打 印 變 量 的 最 終 值 , 其 格 式 與 strobe在目前delta時間步長結束時列印變量的最終值,其格式與 strobe在目前delta時間步長結束時列印變量的最終值,其格式與display類似。
module tb;
initial begin
reg [7:0] a;
reg [7:0] b;
a = 8'h2D;
b = 8'h2D;
#10; // Wait till simulation reaches 10ns
b <= a + 1; // Assign a+1 value to b
$display ("[$display] time=%0t a=0x%0h b=0x%0h", $time, a, b);
$strobe ("[$strobe] time=%0t a=0x%0h b=0x%0h", $time, a, b);
#1;
$display ("[$display] time=%0t a=0x%0h b=0x%0h", $time, a, b);
$strobe ("[$strobe] time=%0t a=0x%0h b=0x%0h", $time, a, b);
end
endmodule
需要注意的是,
$strobe
在時間10ns顯示變量b的最終更新值,也就是0x2E,而
$display
隻有在11ns的下一次模拟delta中才會接收到這個值。
[$display] time=10 a=0x2d b=0x2d
[$strobe] time=10 a=0x2d b=0x2e
[$display] time=11 a=0x2d b=0x2e
[$strobe] time=11 a=0x2d b=0x2e
每當參數清單中的變量或表達式發生變化時,
$monitor
就會自動列印出變量或表達式的值。它達到的效果與每次更新參數後調用
$display
類似。
module tb;
initial begin
reg [7:0] a;
reg [7:0] b;
a = 8'h2D;
b = 8'h2D;
#10; // Wait till simulation reaches 10ns
b <= a + 1; // Assign a+1 value to b
$monitor ("[$monitor] time=%0t a=0x%0h b=0x%0h", $time, a, b);
#1 b <= 8'hA4;
#5 b <= a - 8'h33;
#10 b <= 8'h1;
end
endmodule
請注意, m o n i t o r 就 像 一 個 在 主 線 程 後 台 生 成 運 行 的 任 務 , 它 監 視 并 顯 示 其 參 數 變 量 的 值 變 化 。 新 的 monitor就像一個在主線程背景生成運作的任務,它監視并顯示其參數變量的值變化。新的 monitor就像一個在主線程背景生成運作的任務,它監視并顯示其參數變量的值變化。新的monitor任務可以在仿真過程中任意多次發出。
[$monitor] time=10 a=0x2d b=0x2e
[$monitor] time=11 a=0x2d b=0xa4
[$monitor] time=16 a=0x2d b=0xfa
[$monitor] time=26 a=0x2d b=0x1
為了在顯示函數中列印變量,必須為每個變量給出适當的格式指定符。
Argument | Description |
---|---|
%h, %H | Display in hexadecimal format |
%d, %D | Display in decimal format |
%b, %B | Display in binary format |
%m, %M | Display hierarchical name |
%s, %S | Display as a string |
%t, %T | Display in time format |
%f, %F | Display ‘real’ in a decimal format |
%e, %E | Display ‘real’ in an exponential format |
module tb;
initial begin
reg [7:0] a;
reg [39:0] str = "Hello";
time cur_time;
real float_pt;
a = 8'h0E;
float_pt = 3.142;
$display ("a = %h", a);
$display ("a = %d", a);
$display ("a = %b", a);
$display ("str = %s", str);
#200 cur_time = $time;
$display ("time = %t", cur_time);
$display ("float_pt = %f", float_pt);
$display ("float_pt = %e", float_pt);
end
endmodule
a = 0e
a = 14
a = 00001110
str = Hello
time = 200
float_pt = 3.142000
float_pt = 3.142000e+00
有些字元被認為是特殊字元,因為它們代表其他顯示目的,如換行、制表符和換頁。為了列印這些特殊字元,必須對這些字元的每次出現進行轉義。
\n | New line character |
\t | Tab character |
\ | The \ character |
" | The " character |
%% | The % character |
module tb;
initial begin
$write ("Newline character \n");
$display ("Tab character \tstop");
$display ("Escaping " %%");
/*
// Compilation errors
$display ("Without escaping "); // ERROR : Unterminated string
$display ("Without escaping ""); // ERROR : Unterminated string
*/
end
endmodule
Newline character
Tab character stop
Escaping " %
Verilog初級教程(22)指派間延遲語句與指派内延遲語句
Verilog初級教程(21)Verilog中的延遲控制語句
Verilog初級教程(20)Verilog中的`ifdef 條件編譯語句
Verilog初級教程(19)Verilog中的參數
Verilog初級教程(18)Verilog中的函數與任務
Verilog初級教程(17)Verilog中的case語句
Verilog初級教程(16)Verilog中的控制塊
Verilog初級教程(15)Verilog中的阻塞與非阻塞語句
Verilog初級教程(14)Verilog中的指派語句
Verilog初級教程(13)Verilog中的塊語句
Verilog初級教程(12)Verilog中的generate塊
Verilog初級教程(11)Verilog中的initial塊
Verilog初級教程(10)Verilog的always塊
Verilog初級教程(9)Verilog的運算符
Verilog初級教程(8)Verilog中的assign語句
Verilog初級教程(7)Verilog子產品例化以及懸空端口的處理
Verilog初級教程(6)Verilog子產品與端口
Verilog初級教程(5)Verilog中的多元數組和存儲器
Verilog初級教程(4)Verilog中的标量與向量
Verilog初級教程(3)Verilog 資料類型
Verilog初級教程(2)Verilog HDL的初級文法
Verilog初級教程(1)認識 Verilog HDL
晶片設計抽象層及其設計風格
Verilog以及VHDL所倡導的的代碼準則
FPGA/ASIC初學者應該學習Verilog還是VHDL?