$monitor prints immediately on call, so it prints clk's value before initialization.
Final Answer:
$monitor is called before clk is initialized, so initial print shows unknown value. -> Option C
Quick Check:
Initialize variables before $monitor call [OK]
Hint: Initialize variables before $monitor to avoid unknown prints [OK]
Common Mistakes:
Assuming $monitor waits for variable initialization
Thinking missing semicolon causes error here
Confusing reg and wire for $monitor usage
5. You want to monitor two signals reg [3:0] data; and reg valid; so that the simulation prints their values only when valid changes. Which is the best way to do this using $monitor?
hard
A. $monitor("Data=%b Valid=%b", data, valid);
B. Use an if statement inside $monitor to print only when valid changes.
C. Use $monitor with only valid variable: $monitor("Valid=%b", valid); and add $display for data.
D. Use $monitor with both variables but assign data only when valid changes.
Solution
Step 1: Understand $monitor behavior with multiple variables
$monitor prints whenever any monitored variable changes. Monitoring both data and valid prints on either change.
Step 2: Restrict printing to valid changes only
To print only when valid changes, monitor only valid. But then data won't print updated values automatically.
Step 3: Best practical approach
Monitoring both variables prints all changes, but since data changes only when valid changes, this works well. $monitor("Data=%b Valid=%b", data, valid); is simplest and correct.
Final Answer:
$monitor("Data=%b Valid=%b", data, valid); -> Option A
Quick Check:
Monitor all needed vars; prints on any change [OK]
Hint: Monitor all variables to track changes together [OK]
Common Mistakes:
Trying to put conditions inside $monitor (not allowed)
Monitoring only one variable and missing others' changes
Using $display inside $monitor incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.