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

Functions & Tasks: Default Argument Values

SystemVerilog Advanced Features

Runnable example from the SystemVerilog Functions & Tasks tutorial (Default Argument Values)

Open in IDE
testbench.sv
module tb;
  initial begin
    int r1, r2, r3;

    r1 = scale(5);          // b uses its default of 10
    r2 = scale(5, 3);       // b explicitly overridden to 3
    r3 = scale( , 3);       // a uses its default of 1, b overridden to 3

    $display("r1 = %0d  r2 = %0d  r3 = %0d", r1, r2, r3);
  end

  // "a" defaults to 1, "b" defaults to 10
  function int scale(int a = 1, int b = 10);
    return a * b;
  endfunction
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.