# $monitor is not printing the all value changes when class variable is used inside the system task

**URL:** <https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520>\
**Category:** SystemVerilog\
**Tags:** monitor, SystemVerilog\
**Created:** [May 27, 2014, 12:59pm UTC](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520 "2014-05-27T12:59:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![muralidar](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@muralidar](https://verificationacademy.com/forums/u/muralidar)\
**Post date:** [May 27, 2014, 12:59pm UTC](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/1 "2014-05-27T12:59:08Z")

</div>

Below is my code where iam trying to print the variable value of class using $monitor() function. Here it prints only one value at end of simulation.But As per LRM It is quoted as “When a $monitor task is invoked with one or more arguments, the simulator sets up a mechanism whereby each time a variable or an expression in the argument list changes value—with the exception of the $time”

Please clarify if there is any limitation when we use class variables inside $monitor.  
class self;  
rand bit [2:0] a;  
randc bit [1:0] b;  
endclass

module test;  
self s1;  
initial begin  
repeat(10)  
s1=new;  
s1.randomize();  
end  
initial begin  
$monitor(“Monitor Value of b is =%d”, s1.b);  
end

initial begin  
#400  
$finish;  
end  
endmodule

---

<div class="post-metadata">

**Author:** ![Naven8](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/e495f1/32.png) [@Naven8](https://verificationacademy.com/forums/u/Naven8)\
**Post date:** [May 27, 2014, 1:23pm UTC](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/2 "2014-05-27T13:23:21Z")

</div>

$monitor will print the value only at the end of the time step. If there are multiple changes to same variable in a single timestep(same as your case) then only 1 value(which is last) will be printed.

Put a $display inside the repeat block.

---

<div class="post-metadata">

**Author:** ![muralidar](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@muralidar](https://verificationacademy.com/forums/u/muralidar)\
**Post date:** [May 27, 2014, 2:07pm UTC](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/3 "2014-05-27T14:07:56Z")

</div>

_In reply to [Naven8](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/2):_

I tried with $display. It is working. But if i give some delay in repeat block like below, then the all the random values should be printed. But the output is same.  
Can i know the reason? How can i print all the random values using $monitor in my scenario?  
In this case how a time stamp can be defined?

initial begin  
repeat(10)  
#10;  
s1=new;  
s1.randomize();  
end

---

<div class="post-metadata">

**Author:** ![Naven8](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/e495f1/32.png) [@Naven8](https://verificationacademy.com/forums/u/Naven8)\
**Post date:** [May 27, 2014, 2:30pm UTC](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/4 "2014-05-27T14:30:10Z")

</div>

_In reply to [muralidar](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/3):_

I think you should go through section “4. Scheduling semantics” in LRM. This will clarify all your doubts.

---

<div class="post-metadata">

**Author:** ![Naven8](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/e495f1/32.png) [@Naven8](https://verificationacademy.com/forums/u/Naven8)\
**Post date:** [May 27, 2014, 3:17pm UTC](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/5 "2014-05-27T15:17:16Z")

</div>

_In reply to [Naven8](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/4):_

First of all vcs is not allowing me to monitor dynamic variables. Which tool you are using? (I am not sure how monitor will behave when object is not created.)

In your first attempt you are creating object multiple times but randomizing only once.

```verilog

// begin-end is missing after repeat
repeat(10) 
s1=new;
s1.randomize();

```

2nd time also the same thing happening(missing begin-end).

```verilog
repeat(10) 
#10;
s1=new;
s1.randomize();
end

```

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [May 27, 2014, 3:31pm UTC](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/6 "2014-05-27T15:31:48Z")

</div>

_In reply to [Naven8](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/5):_

I would never use $monitor. You are only allowed one active $monitor in your entire simulation. $monitor was used as an interactive debugging aid for Verilog-XL, which used Verilog as its tool command language.

As Naven8 write, there is also a problem if you try to reference a null class variable at time 0, you will get a fatal error.

If you really want to see the result of a class object after calling randomize(), then create a post\_randomize() method in the class to display the results.

---

<div class="post-metadata">

**Author:** ![muralidar](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@muralidar](https://verificationacademy.com/forums/u/muralidar)\
**Post date:** [May 28, 2014, 5:54am UTC](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/7 "2014-05-28T05:54:48Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/monitor-is-not-printing-the-all-value-changes-when-class-variable-is-used-inside-the-system-task/29520/6):_

Thanks Naven8 for your replay. I am using questasim to compile the code. Begin end is there in my code.
