Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

`define with default arguments

SystemVerilog Advanced Features

Runnable example from the SystemVerilog `define Macro tutorial (`define with default arguments)

Open in IDE
testbench.sv
`define   ADD(name="INST", a=5, b)    $display("%s a=%0d b=%0d sum=%0d", name, a, b, a + b);

module tb;  
  initial begin            
    // Text substitute a with 3 and b with 4
    `ADD("ADDER", 3, 4)    
    
    // name is left empty, so its default ("INST") is used instead; a and b are both explicitly passed
    `ADD( , 3, 1)
    
    // First argument
    `ADD(, , 5)
    
    // Whitespace between `ADD and (
    `ADD ("SPACE", 1, 2)
  end  
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.