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

Structure Comparison With Union

SystemVerilog Data Types

Compare how struct behaves with union

Open in IDE
Related tutorial:
testbench.v
typedef struct packed {
  bit [31:0] raw;
  bit [15:0] high;
  bit [15:0] low;
} data_struct_t;

module tb;
  initial begin
    data_struct_t d;

    d.raw = 32'hDEAD_BEEF;

    $display ("raw  = 0x%0h", d.raw);
    $display ("high = 0x%0h", d.high);
    $display ("low  = 0x%0h", d.low);
  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.