Welcome ! This website will help YOU (recent graduates/professionals) learn verification languages like SystemVerilog and UVM. Register for free and access more content !

There are certain standard system tasks and functions available in Verilog for routine operations, all having a format like $<keyword>(). The list of system tasks defined in Verilog HDL is very long, and only selected most useful functions will be discussed here.

Display Tasks

$display is the main system task for printing the values of variables, nets, and expressions onto the console. This is very useful to debug errors due to incorrect functionality in the design.

$display (<list_of_arguments>);
$write (<list_of_arguments>);
 
module tb;
  initial begin
    $display ("This ends with a new line ");
    $write ("This does not,");
    $write ("like this. To start new line, use newline char \n");
    $display ("Hi there !");
  end
endmodule
 
Simulation Log
ncsim> run
This ends with a new line 
This does not,like this. To start new line, use newline char 
Hi there !
ncsim: *W,RNQUIE: Simulation is complete.

$strobe helps to print the final values of variables at the end of the current delta time-step and has a similar format like $display().

 
module tb;
  initial begin
    reg [7:0] a;
    reg [7:0] b;
 
    a = 8'h2D;
    b = 8'h2D;
 
    #10;                  // Wait till simulation reaches 10ns
    b <= a + 1;           // Assign a+1 value to b
 
    $display ("[$display] time=%0t a=0x%0h b=0x%0h", $time, a, b);
    $strobe  ("[$strobe]  time=%0t a=0x%0h b=0x%0h", $time, a, b);
 
    #1;
    $display ("[$display] time=%0t a=0x%0h b=0x%0h", $time, a, b);
    $strobe  ("[$strobe]  time=%0t a=0x%0h b=0x%0h", $time, a, b);
 
  end
endmodule
 

Note that $strobe shows the final updated value of the variable b at time 10ns which is 0x2E, and $display picks that up only in the next simulation delta at 11ns.

Simulation Log
ncsim> run
[$display] time=10 a=0x2d b=0x2d
[$strobe]  time=10 a=0x2d b=0x2e
[$display] time=11 a=0x2d b=0x2e
[$strobe]  time=11 a=0x2d b=0x2e
ncsim: *W,RNQUIE: Simulation is complete.
ncsim> exit

$monitor helps to automatically print out variable or expression values whenever the variable or expression in its argument list changes. So, it achieves a similar effect like calling $display after every time any of its arguments get updated.

 
module tb;
  initial begin
    reg [7:0] a;
    reg [7:0] b;
 
    a = 8'h2D;
    b = 8'h2D;
 
    #10;                  // Wait till simulation reaches 10ns
    b <= a + 1;           // Assign a+1 value to b
 
    $monitor ("[$monitor] time=%0t a=0x%0h b=0x%0h", $time, a, b);
 
    #1 b <= 8'hA4;
    #5 b <= a - 8'h33;
    #10 b <= 8'h1;
 
  end
endmodule
 

Note that $monitor is like a task is spawned to run in the background of the main piece of code that monitors and displays value changes of its argument variables. A new $monitor task can be issued any number of times during simulation.

Simulation Log
ncsim> run
[$monitor] time=10 a=0x2d b=0x2e
[$monitor] time=11 a=0x2d b=0xa4
[$monitor] time=16 a=0x2d b=0xfa
[$monitor] time=26 a=0x2d b=0x1
ncsim: *W,RNQUIE: Simulation is complete.

Format Specifications

In order to print variables inside display functions, appropriate format specifiers have to be given for each variable.

Argument Description
%h, %H Display in hexadecimal format
%d, %D Display in decimal format
%b, %B Display in binary format
%m, %M Display hierarchical name
%s, %S Display as a string
%t, %T Display in time format
%f, %F Display 'real' in a decimal format
%e, %E Display 'real' in an exponential format
 
module tb;
  initial begin
    reg [7:0]  a;
    reg [39:0] str = "Hello";
    time       cur_time;
    real       float_pt;
 
    a = 8'h0E;
    float_pt = 3.142;
 
    $display ("a = %h", a);
    $display ("a = %d", a);
    $display ("a = %b", a);
 
    $display ("str = %s", str);
    #200 cur_time = $time;
    $display ("time = %t", cur_time);
    $display ("float_pt = %f", float_pt);
    $display ("float_pt = %e", float_pt);
  end
endmodule
 
Simulation Log
ncsim> run
a = 0e
a =  14
a = 00001110
str = Hello
time =                  200
float_pt = 3.142000
float_pt = 3.142000e+00
ncsim: *W,RNQUIE: Simulation is complete.

Some characters are considered special since they stand for other display purposes like new-line, tabs and form feeds. In order to print these special characters, each occurrence of such characters have to be escaped.

Argument Description
\n Newline character
\t Tab character
\\ The \ character
\" The \" character
%% The % character
 
module tb;
  initial begin
    $write ("Newline character \\n \n");
    $display ("Tab character\tstop");
    $display ("Escaping \\ \" %%");
 
/*    
    // Compilation errors
    $display ("Without escaping \");       // ERROR : Unterminated string
    $display ("Without escaping "");       // ERROR : Unterminated string
*/
  end
endmodule
 
Simulation Log
ncsim> run
Newline character \n 
Tab character	stop
Escaping \ " %
ncsim: *W,RNQUIE: Simulation is complete.

Was this article helpful ?

We use cookies to personalize content and ads, to provide social media features and to analyze our traffic. You consent to our cookies if you continue to use our website. To find out more about the cookies we use and how to delete them, see our privacy policy.

  I accept cookies from this site.
Agree
EU Cookie Directive plugin by www.channeldigital.co.uk