Consider the following Verilog code snippet. What will be printed on the console when it runs?
module test; reg a = 0; initial begin $display("Value of a is %d", a); a = 1; $display("Value of a changed to %d", a); end endmodule
Remember that $display prints the value at the time it is called.
The first $display prints the initial value of a which is 0. Then a is set to 1, and the second $display prints the updated value.
Look at this Verilog code using $monitor. What output will it produce?
module test; reg a = 0; initial begin $monitor("At time %0t, a = %d", $time, a); #5 a = 1; #5 a = 0; #5 $finish; end endmodule
$monitor prints whenever a monitored variable changes, including at time 0.
$monitor prints the initial values at time 0, then prints again whenever a changes at times 5 and 10.
Examine this Verilog code. It uses $monitor but prints nothing. What is the reason?
module test; reg a = 0; initial begin $monitor("a = %d", a); end endmodule
Think about simulation time and when $monitor prints.
$monitor prints immediately at time 0, but if the simulation ends instantly (no delays or events), the output may not appear. Here, the simulation ends immediately after initial block.
Which of the following $display statements is syntactically incorrect in Verilog?
Check the commas between arguments carefully.
Option A misses a comma between the format string and the variable, causing a syntax error.
Given this Verilog code, how many lines will $monitor print before simulation ends?
module test; reg a = 0; reg b = 1; initial begin $monitor("Time %0t: a=%d, b=%d", $time, a, b); #3 a = 1; #2 b = 0; #5 a = 0; #1 $finish; end endmodule
$monitor prints at time 0 and whenever any monitored variable changes.
$monitor prints initially at time 0, then at time 3 when a changes, at time 5 when b changes, and at time 10 when a changes again. Total 4 prints.
