Display And Monitor
Coddy Verilog 여정의 기초 섹션에 포함된 레슨. 90개 중 75번째.
$display와 $monitor는 시뮬레이션의 정보를 출력하는 데 사용되는 시스템 태스크입니다. 이를 통해 설계 내부에서 어떤 일이 일어나고 있는지 확인할 수 있습니다.
$display
$display는 실행되는 순간 메시지를 한 번 출력합니다.
구문:
$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는 변수 중 하나라도 변경될 때마다 자동으로 메시지를 출력합니다.
구문:
$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 대 $monitor
| $display | $monitor | |
|---|---|---|
| 출력되는 시점 | 실행될 때 한 번 | 변수가 변경될 때마다 |
| 출력 횟수 | 호출한 횟수만큼 | 계속해서 (변경될 때까지) |
| 용도 | 헤더, 테스트 메시지 | 변경되는 신호 추적 |
일반적인 형식 지정자
| 지정자 | 의미 | 예제 |
|---|---|---|
%b | Binary | $display("%b", a); |
%d | 십진수 | $display("%d", count); |
%h | 16진수 | $display("%h", data); |
%t | Time | $display("%t", $time); |
%0t | Time (공백 없음) | $display("%0t", $time); |
%s | 문자열 | $display("%s", "Hello"); |
중요한 규칙
| 규칙 | 설명 |
|---|---|
$display는 한 번 출력 | 헤더와 최종 결과에 적합 |
$monitor는 변경 시 출력 | 신호를 감시하는 데 적합 |
활성 상태의 $monitor는 하나만 가능 | 마지막 것이 이전 것을 덮어씀 |
중지하려면 $finish 사용 | 그렇지 않으면 시뮬레이션이 영원히 실행될 수 있음 |
챌린지
이 testbench에 누락된 $display 및 $monitor 문을 Add하세요.
수행할 작업:
- header를 출력하도록
$display를 Add하세요: "Testing OR Gate" - 신호가 변경될 때마다 time, x, y, z를 출력하도록
$monitor를 Add하세요. Format: "Time %0t: x=%b, y=%b, z=%b" - 마지막에 "Test complete"를 출력하도록
$display를 Add하세요.
직접 해보기
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: time, 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 컴파일러