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

combo logic with assign

Verilog Assignments

Example of using 'assign' statement for combinational logic

Open in IDE
Related tutorial:
design.v
module combo (	input 	a,
      			input	b,
              	input	c,
              	input	d,
  	            output  o);
  
  assign o = ~((a & b) | c ^ d);
  
endmodule
testbench.v
module tb;
  reg a, b, c, d;
  wire o;
  
  // Instantiate the design
  combo 	c0 ( .a(a),
                .b(b),
                .c(c),
                .d(d),
                .o(o));
  
  // Drive some stimulus to test the design
  initial begin
    // 1. Initialize variables to 0 in the beginning
    a <= b <= c <= d <= 0;
    
    // 2. After every 10 time units, drive some random value
    // to all the signals
    for (integer i = 0; i < 10; i += 1) begin
      #10;
      a <= $random;
      b <= $random;
      c <= $random;
      d <= $random;
    end
  end
  
  // Code used to dump waveform file
  initial begin
    $dumpvars;
    $dumpfile("dump.vcd");
  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.