Keywords: $monitor, $monitoron, $monitoroff
The format of $monitor is exactly the same as $display The difference is that an output occurs on any change in the variables, rather than at specified times. Thus the $monitor command established a list of variable which are watched, and in practice it is written to be executed at the beginning of the simulation.
Monitoring can be enabled or disabled using $monitoron or $monitoroff respectively. Monitoring is on by default at the beginning of a simulation. The example below shows how a simulation can be monitored.
module myTest; integer a,b; initial begin a = 2; b = 4; forever begin #5 a = a + b; #5 b = a - 1; end // forever begin end // initial begin initial #40 $finish; initial begin $monitor($time, " a = %d, b = %d", a, b); end // initial begin endmodule // myTest
0 a = 2, b = 4 5 a = 6, b = 4 10 a = 6, b = 5 15 a = 11, b = 5 20 a = 11, b = 10 25 a = 21, b = 10 30 a = 21, b = 20 35 a = 41, b = 20