Display와 Monitor
Coddy Verilog 여정의 기초 섹션에 포함된 레슨 — 90개 중 75번째.
$display와 $monitor는 시뮬레이션에서 정보를 출력하는 데 사용되는 시스템 작업입니다. 이들은 디자인 내부에서 무슨 일이 일어나고 있는지 확인하는 데 도움을 줍니다.
$display
$display는 실행되는 그 순간 메세지(message)를 한 번 출력합니다.
구문:
$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 중 하나라도 변경될 때마다 자동으로 메세지를 출력합니다.
구문:
$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 | |
|---|---|---|
| 출력 시점 | 실행될 때 한 번 | 변수가 변경될 때마다 |
| 출력 횟수 | 호출하는 횟수만큼 | 지속적으로 (변경될 때까지) |
| 용도 | 헤더, 테스트 메시지 | 변화하는 신호 추적 |
자주 사용되는 Format Specifier
| Specifier | 의미 | 예시 |
|---|---|---|
%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만 활성화됨 | 마지막 $monitor가 이전 $monitor를 덮어씀 |
중지하려면 $finish를 사용함 | 그렇지 않으면 Simulation이 영원히 실행될 수 있음 |
챌린지
이 testbench에 누락된 $display 및 $monitor 구문을 추가하세요.
수행할 작업:
- header를 출력하는
$display를 추가하세요: "Testing OR Gate" - 신호가 변경될 때마다 time, x, y, z를 출력하는
$monitor를 추가하세요. Format: "Time %0t: x=%b, y=%b, z=%b" - end 부분에 "Test complete"를 출력하는
$display를 추가하세요
직접 해보기
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이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.