Display And Monitor
CoddyのVerilogジャーニー「基礎」セクションの一部。レッスン 75/90。
$display と $monitor は、シミュレーションから情報を出力するために使用されるシステムタスクです。設計内部で何が起きているかを確認するのに役立ちます。
$display
$displayは、実行された時点でメッセージを1回出力します。
構文:
$display("message", variables);例:
initial begin
$display("Simulation started");
#10;
$display("Time 10");
#10;
$display("Time 20");
end出力:
Simulation started
Time 10
Time 20$monitor
$monitor は、variables のいずれかが変更されるたびにmessage を自動的に出力します。
構文:
$monitor("message", variables);例:
initial begin
a = 0; b = 0;
$monitor("Time %0t: a=%b, b=%b", $time, a, b);
#10 a = 1;
#10 b = 1;
#10 a = 0;
end出力:
Time 0: a=0, b=0
Time 10: a=1, b=0
Time 20: a=1, b=1
Time 30: a=0, b=1$display vs $monitor
| $display | $monitor | |
|---|---|---|
| 出力されるタイミング | 実行時に1回 | variables が変化するたびに |
| 回数 | 呼び出した回数だけ | 継続的に(変更されるまで) |
| 用途 | header、テストメッセージ | 変化する信号の追跡 |
一般的なフォーマット指定子
| 指定子 | 意味 | 例 |
|---|---|---|
%b | Binary | $display("%b", a); |
%d | 10進数 | $display("%d", count); |
%h | 16進数 | $display("%h", data); |
%t | Time | $display("%t", $time); |
%0t | Time(スペースなし) | $display("%0t", $time); |
%s | 文字列 | $display("%s", "Hello"); |
重要なルール
| ルール | 説明 |
|---|---|
$display は一度だけ出力する | header と最終結果に適している |
$monitor は変更時に出力する | 信号の監視に適している |
有効にできる $monitor は1つだけ | 最後のものが以前のものを上書きする |
停止するには $finish を使用する | そうしないとシミュレーションが永遠に実行される可能性がある |
チャレンジ
不足している $display と $monitor ステートメントをこのテストベンチに Add してください。
実行すること:
- Add
$displayを使ってヘッダーを出力します: "Testing OR Gate" - Add
$monitorを使って、いずれかの信号が変化するたびに time、x、y、z を出力します。Format: "Time %0t: x=%b, y=%b, z=%b" - 最後に Add
$displayを使って "Test complete" を出力します
自分で試してみよう
module or_gate (
input x,
input y,
output z
);
assign z = x | y;
endmodule
module testbench;
reg x, y;
wire z;
or_gate dut (
.x(x),
.y(y),
.z(z)
);
initial begin
// TODO: $display ヘッダー "Testing OR Gate" を追加
// TODO: 時間、x、y、z を追跡する $monitor を追加
// 形式: "Time %0t: x=%b, y=%b, z=%b"
// 刺激を適用
x = 0; y = 0; #10;
x = 0; y = 1; #10;
x = 1; y = 0; #10;
x = 1; y = 1; #10;
// TODO: $display "Test complete" を追加
$finish;
end
endmoduleこのレッスンには短いクイズがあります。レッスンを始めて解答し、進捗を記録しましょう。
基礎のすべてのレッスン
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge14Testbench Basics
What Is A TestbenchCreating StimulusDisplay And MonitorDumpfile And DumpvarsUsing System TasksRecap - Full Testbench3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic自分で練習してみよう: Verilogオンラインコンパイラ