Saurabh Singh
Saurabh Singh

Reputation: 5

The output of the following code is unexpected:

I am trying to display time. But it returns the value 0. What's wrong?

CODE:

module hello_world;
integer in_reg;
initial
begin
  in_reg = 3'd2;
  $monitor($time, " In register value = %b\n",in_reg[2:0]);
end
endmodule

OUTPUT:

0 In register value = 010

Upvotes: 0

Views: 75

Answers (2)

Pradyuman Bissa
Pradyuman Bissa

Reputation: 191

Try this, the below code will print in_reg contents 10 times every 10ns, the simulation time would be displayed as 10,20,...etc

`timecale 1ns/1ps
module hello_world;
integer in_reg;  
initial
begin
  in_reg = 3'd2;
 repeat(10)
 begin
  #10;
  $display($time, " In register value = %b\n",in_reg); 
 end
end
endmodule

Upvotes: 0

Matthew
Matthew

Reputation: 13937

Nothing is wrong. When the $monitor statement outputs its line, simulation time is 0.

As I guess you know, $monitor outputs a line whenever any of its inputs changes. It does not do this for $time, however, because it makes little sense to do so. (When would it output a line? Every ns? Every ps? Every fs?)

So, your code sets in_reg to 3'd2 and then $monitor displays that. Then the simulation finishes. Nothing else happens.

Upvotes: 2

Related Questions