Print signal changes each cycle with $monitor
Print a line whenever any watched signal changes with $monitor, set up once, and learn why a second call silently replaces the first.
$display prints when you tell it to. $monitor prints when something changes, which suits a counter or a handshake you want to follow cycle by cycle without scattering $display calls. Call it once from an initial block and it reports at the end of every time step in which a listed argument changed.
`timescale 1ns/1ps
module tb;
reg clk = 1'b0;
reg [3:0] count = 4'd0;
always #5 clk = ~clk;
always @(posedge clk) count <= count + 1;
initial begin
$monitor("t=%0d count=%0d", $time, count);
#44 $finish;
end
endmodulet=0 count=0
t=5 count=1
t=15 count=2
t=25 count=3
t=35 count=4The argument $time does not trigger a print on its own. Only the other arguments count as change events, which is why clk is left out here: listing it would print twice per cycle. The first line at time 0 appears because $monitor prints once when it is called.
There is one monitor per simulation. A second $monitor call replaces the first without a warning, so two modules that each call it fight silently. $monitoroff and $monitoron pause and resume it, and $strobe is the tool for a single print at the end of one time step.