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: Calling with Named Arguments

SystemVerilog Advanced Features

Runnable example from the SystemVerilog Functions & Tasks tutorial (Calling with Named Arguments)

Open in IDE
testbench.sv
module tb;
  initial begin
    $display("scale(.b(3))        = %0d", scale(.b(3)));         // a defaults to 1
    $display("scale(.b(3), .a(5)) = %0d", scale(.b(3), .a(5)));  // named args, any order
    $display("scale(5, .b(3))     = %0d", scale(5, .b(3)));      // positional then named
  end

  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.