Printing Statements / Methods in Verilog, SystemVerilog, and UVM

How to Print Statements in Verilog, SystemVerilog, and UVM

In this comprehensive guide, we cover the different methods to print statements in Verilog, SystemVerilog, and UVM. Whether you are working on .v files or .sv files, understanding how to effectively use printing functions is crucial for debugging and developing your HDL code.

Verilog Printing Methods

  1. $display: Prints messages at the end of the current time step. Ideal for general-purpose message printing.
    $display("This is a display statement at time %0t", $time);
    
  2. $monitor: Continuously monitors and prints whenever there is a change in the monitored variable or expression.
    $monitor("At time %0t: variable = %0d", $time, variable);
    
  3. $strobe: Ensures that only the last strobe statement of the current time step is printed.
    $strobe("This is a strobe statement at time %0t", $time);
    

SystemVerilog Printing Methods

  1. $display: General-purpose printing function.
    $display("SystemVerilog display at time %0t", $time);
    
  2. $monitor: For continuous monitoring of variables.
    $monitor("At time %0t: variable = %0d", $time, variable);
    
  3. $strobe: Ensures only the last message in the current time step is printed.
    $strobe("SystemVerilog strobe at time %0t", $time);
    
  4. $write: Similar to $display but does not add a newline at the end.
    $write("SystemVerilog write without newline at time %0t", $time);
    
  5. $fatal, $error, $warning, $info: For different severity levels.
    $fatal("Fatal error occurred at time %0t", $time);
    $error("Error message at time %0t", $time);
    $warning("Warning at time %0t", $time);
    $info("Informational message at time %0t", $time);
    

UVM Reporting Macros

  1. uvm_info: For informational messages.
    `uvm_info("INFO", "This is an informational message", UVM_MEDIUM)
    
  2. uvm_warning: For warning messages.
    `uvm_warning("WARNING", "This is a warning message")
    
  3. uvm_error: For error messages.
    `uvm_error("ERROR", "This is an error message")
    
  4. uvm_fatal: For fatal messages that terminate the simulation.
    `uvm_fatal("FATAL", "This is a fatal message") 

Key Considerations:

  • Verbosity Levels: You can control the level of output by using verbosity levels in UVM reporting.
  • Time Stamping: Use $time to display the current simulation time along with the printed messages.
  • File Handling: Use $fopen, $fwrite, and $fclose to write messages to files instead of the console.

Timing Control in Verilog and SystemVerilog

  • #: Delay control.
    #10 $display("Printed after 10 time units");
    
  • @: Event control (sensitivity list).
    always @(posedge clk) $display("Printed at the positive edge of clk");