Learn about SystemVerilog data types including integer, logic, real, nets, enums, strings, and more with examples and code snippets.
๐น Introduction
SystemVerilog provides a rich set of data types that help in modeling both hardware and testbenches efficiently. Unlike older Verilog, it introduces strong typing, signed/unsigned control, and advanced user-defined types.
๐น Integer Data Types
Common integer types in SystemVerilog include:
bitโ 2-state (0,1)logicโ 4-state (0,1,X,Z)byteโ 8-bit signedshortintโ 16-bit signedintโ 32-bit signedlongintโ 64-bit signed
// Example: Integer declarations
bit b1; // 2-state, 1 bit
logic l1; // 4-state, 1 bit
byte a = 8'hFF;
int count;
longint big_num;
โก Signed vs Unsigned
int a = -5;
bit [7:0] u = 8'hFF; // unsigned
logic signed [7:0] s = -8'd5; // signed
๐น Real Data Types
Used for floating-point numbers:
realshortreal
real pi = 3.14159;
shortreal temp = 23.5;
๐น Nets vs Variables
Nets (like wire, tri, etc.) represent physical connections.
Variables (logic, int, etc.) hold values.
wire w1;
logic l1;
assign w1 = l1; // nets are driven by continuous assignments
๐น Enumerated Types
Enums make code more readable and self-documenting, especially in FSMs.
typedef enum logic [1:0] {IDLE=2'b00, BUSY=2'b01, DONE=2'b10} state_t;
state_t curr_state;
๐น String Data Type
SystemVerilog supports dynamic strings with built-in operators and methods.
string s1 = "Hello";
s1 = {s1, " World!"}; // concatenation
$display("Length = %0d", s1.len());
๐น Events
event ev;
initial begin
-> ev; // trigger
@ (ev); // wait for event
end
โ Key Takeaways
- Use
bitfor 2-state,logicfor 4-state modeling. enumimproves FSM readability and safety.- Strings are dynamic and very useful in testbenches.
- Variables vs Nets distinction is important for RTL coding.
