Skip to main content

Verilog Command-Line Input: $plusargs for Testbench Control

· loading · loading · ·
Hardware Design Verilog Command Line Plusargs Testbench Simulation Control Hardware Verification
Hardware Design
Axolot Logic
Author
Axolot Logic
Digital Design Engineer
Table of Contents
Verilog HDL Series - This article is part of a series.
Part 20: This Article

📥 Command-Line Input in Verilog
#

In Verilog testbenches, accepting command-line arguments makes your simulations parameterizable and reusable. This is especially useful for passing different seed, mode, or testcase values without modifying the testbench code.


🔹 $value$plusargs
#

Used to capture arguments with values, passed in the form +ARG=VALUE.

$value$plusargs("SEED=%d", seed);

This call returns 1 and assigns the value to seed if +SEED=123 is passed at runtime. Otherwise, it returns 0.

✅ Example:
#

integer seed;
initial begin
  if (!$value$plusargs("SEED=%d", seed)) begin
    seed = 42;  // Default fallback
  end
  $display("Using seed: %0d", seed);
end

🔹 $test$plusargs
#

Checks for the presence of a flag (boolean-style argument) without an associated value.

if ($test$plusargs("VERBOSE")) begin
  $display("Verbose mode is ON.");
end

Returns 1 if +VERBOSE was passed, otherwise 0.


🖥️ Simulation Command
#

vvp a.out +SEED=123 +VERBOSE

🧠 Summary Table
#

CategoryFunctionDescription
Value input$value$plusargs("FORMAT", var)Retrieves and assigns value
Flag detection$test$plusargs("NAME")Checks if flag is present

module tb_cmd_args;

    integer seed;
    bit verbose;

    initial begin
        // Get numeric seed from command line
        if (!$value$plusargs("SEED=%d", seed)) begin
            seed = 0;  // Default seed
        end

        // Check for +VERBOSE flag
        if ($test$plusargs("VERBOSE")) begin
            verbose = 1;
            $display("Verbose mode is ON.");
        end else begin
            verbose = 0;
        end

        $display("Simulation Seed = %0d", seed);
        #10 $finish;
    end

endmodule

Verilog HDL Series - This article is part of a series.
Part 20: This Article

Related

Verilog Hierarchical Reference: Accessing Internal Signals
· loading · loading
Hardware Design Verilog Hierarchical Reference Force Release Testbench Simulation Debugging Hardware Verification
Hardware Design
Verilog Simulation Basics & Testbench Design
· loading · loading
Hardware Design Verilog Simulation Testbench Timescale Simulation Regions Hardware Verification
Hardware Design
Verilog Delay Controls: #Delay, @Event, Wait
· loading · loading
Hardware Design Verilog Delay Event Control Wait Statement Simulation Testbench
Hardware Design
Verilog System Functions & Tasks for Simulation
· loading · loading
Hardware Design Verilog System Functions Verilog Tasks Simulation Testbench Randomization
Hardware Design
Verilog VCD: Waveform Dumping for Simulation Analysis
· loading · loading
Hardware Design Verilog VCD Waveform Viewing Simulation Analysis Testbench GTKWave
Hardware Design
Verilog initial Block: Testbench & Simulation Essentials
· loading · loading
Hardware Design Verilog Initial Verilog Testbench Simulation Hardware Verification Digital Design
Hardware Design