Home / Learn Verilog / Structs and Unions
Structs and Unions
Group related signals.
The gistGroup related signals.
The idea, explained simply
In plain terms
A packed struct is a vector with named fields; you can pass it around as one signal.
Why we use it
Cleaner ports and registers.
Under the hood
typedef struct packed { ... } name_t;
Real-world use
- Everyday RTL design
- FPGA and ASIC projects
- Testbenches and debugging
Try it
Pack and unpack by hand (what a struct does)Verilog: edit and run
A packed struct does the same with named fields.
typedef struct packed {\n logic [1:0] op;\n logic [2:0] a;\n logic [2:0] b;\n} instr_t;\n\ninstr_t i;\nassign i = 8'b10_101_001;\n// i.op == 2, i.a == 5, i.b == 1Careful:This simulator runs the core of SystemVerilog (logic, always_ff, always_comb, enum, typedef, int, loops with int, break/continue, inside, immediate assert). Features shown only in the grey code box need a full simulator (Icarus -g2012, Verilator, Questa, VCS, Xcelium).
Quick quiz
1. Packed struct is...
Bits in order.