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

Verilog ANSI Ports

Verilog Ports

How ports are declared in Verilog 2001 ANSI-C style

Open in IDE
design.v
module mydesign ( input [3:0] a,
                 input [3:0] b,
                 output [3:0] c);


`ifdef REG
  reg [3:0] c;
  
  always @ (a or b) 
    c = a + b;
`else
    assign c = a + b;
`endif  
endmodule
testbench.v
module tb;
  wire [3:0] c;
  reg [3:0] a, b;
  
  mydesign d0 ( .a(a),
               .b(b),
               .c(c));
  
  initial begin
    a <= 0;
    b <= 0;
    $monitor ("%0t a=%0d b=%0d c=%0d", $time, a, b, c);
    
    for (int i = 0 ;i < 5; i+= 1) begin
      #10;
      a <= $random;
      b <= $random;
    end
    
  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.