Display system tasks are mainly used to display informational and debug messages to track the flow of simulation from log files and also helps to debug faster. There are different groups of display tasks and formats in which they can print values.

Display/Write Tasks

Syntax

Both $display and $write display arguments in the order they appear in the argument list.


$display(<list_of_arguments>);
$write(<list_of_arguments>);

$write does not append the newline character to the end of its string, while $display does and can be seen from the example shown below.

Example


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 
");
    $display ("This always start on a new line !");
  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.

Verilog Strobes

$strobe prints 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

Verilog Continuous Monitors

$monitor helps to automatically print out variable or expression values whenever the variable or expression in its argument list changes. It achieves a similar effect of 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 that is spawned to run in the background of the main thread which 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.

Verilog Format Specifiers

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

ArgumentDescription
%h, %HDisplay in hexadecimal format
%d, %DDisplay in decimal format
%b, %BDisplay in binary format
%m, %MDisplay hierarchical name
%s, %SDisplay as a string
%t, %TDisplay in time format
%f, %FDisplay 'real' in a decimal format
%e, %EDisplay '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.

Verilog Escape Sequences

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.

ArgumentDescription
Newline character
Tab character
The character
"The " character
%%The % character

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