What is difference between $display and $monitor in verilog?

Both $display and $monitor in verilog are built in system task. Both enters a new line character at the end of displayed variable. Difference is however from the perspective of their invocation and duration. $monitor, once invoked keeps printing the variable continuously whenever there is change in the value of any of variable in the list. $display on the other prints the specified variables value only once and then terminates. To display value of listed variables at any other instant would need another invocation of $display task.
For e.g., let us take a variable temp that changes value at following instant
$Time : temp
10 : 3
20 : 7
30 : 9

Just one invocation of $monitor("temp = ",temp); would print
temp = 3
temp = 7
temp = 3

while we have to type $display at three place in the code to get the same result.

1 comment:

Anonymous said...

$monitor task has another advantage when combined with $monitoron and $monitoroff tasks. These two tasks can be used to enable and disable monitoring of list of variables. $monitoron enables the $monitor for desired region of verilog code and $monitoroff disables $monitor task.