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

Module Instantiation Ordered Ports

Verilog Module

Instantiation of module with ordered port list

Open in IDE
design.v
module mydesign ( input [3:0] a,
                 input [3:0] b,
                 output reg [3:0] c);
 
  always @ (a or b) 
    c = a ^ b | a & b;

endmodule
testbench.v
module tb;
  wire [3:0] z;
  reg [3:0]  x, y;
  
  // Connection made by ordered list
  mydesign d0 ( x, y, z);
  
  initial begin
    x <= 0;
    y <= 0;
    $monitor ("%0t x=%0d y=%0d z=%0d", $time, x, y, z);
    
    for (int i = 0 ;i < 5; i+= 1) begin
      #10;
      x <= $random;
      y <= $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.