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

logic: Example 2: Driven Purely from a Procedural Block

SystemVerilog Data Types

Runnable example from the SystemVerilog logic tutorial (Example 2: Driven Purely from a Procedural Block)

Open in IDE
testbench.sv
module tb;
  logic [1:0] sel;
  logic [7:0] a, b, c, d;
  logic [7:0] mux_out;

  // mux_out is driven only from inside this procedural block
  always_comb begin
    case (sel)
      2'b00: mux_out = a;
      2'b01: mux_out = b;
      2'b10: mux_out = c;
      2'b11: mux_out = d;
    endcase
  end

  initial begin
    a = 8'h11; b = 8'h22; c = 8'h33; d = 8'h44;

    sel = 2'b00; #1;
    $display ("sel=%0b mux_out=0x%0h", sel, mux_out);

    sel = 2'b10; #1;
    $display ("sel=%0b mux_out=0x%0h", sel, mux_out);

    sel = 2'b11; #1;
    $display ("sel=%0b mux_out=0x%0h", sel, mux_out);
  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.