SV Question
SV Question
Interview Questions
Preface
SystemVerilog stands as the cornerstone of modern functional verification. With its
vast set of features ranging from object-oriented programming to constrained random
verification and assertions, mastering SV is crucial for cracking top-level VLSI interviews.
This document contains 25 carefully curated high-level interview questions along with
deep and insightful answers. Every question is designed to test not just syntax, but real-
world understanding of how SystemVerilog is applied in testbenches, UVM, and ASIC
design environments.
Each section is structured to deepen your conceptual understanding and sharpen your
problem-solving skills.
Page 1
SystemVerilog Interview Collection VeriCore Academy
• struct groups variables under a single name; all variables exist simultaneously.
• union allows only one variable to occupy memory at any time (overlapping mem-
ory).
• class is a dynamic object with OOP features such as inheritance and polymorphism.
Example:
typedef struct {
bit [3:0] id;
bit [7:0] data;
} packet_t;
typedef union {
bit [31:0] raw;
struct {
bit [7:0] header;
bit [23:0] payload;
} fields;
} u_data;
class transaction;
rand bit [7:0] addr;
rand bit [31:0] data;
endclass
Key Points:
• ‘class‘ allows OOP principles and dynamic behavior, making it ideal for testbench
modeling.
Page 2
SystemVerilog Interview Collection VeriCore Academy
Q2. Explain ‘typedef struct packed‘ and its practical use in de-
sign/verification.
Answer: The ‘typedef struct packed‘ keyword defines a packed structure, where all
members are packed next to each other with no padding, allowing it to be treated like a
single vector.
Syntax:
• Useful for representing bus protocols and aligning with memory layouts.
Example Use:
instruction_t instr;
logic [31:0] raw_instr;
raw_instr = 32’hABCD1234;
instr = instruction_t’(raw_instr);
Page 3
SystemVerilog Interview Collection VeriCore Academy
• Automatic arrays: Stack-allocated arrays created fresh each time a task is called.
initial begin
dyn_array = new[8]; // Allocates size at runtime
end
• Best for Testbenches: Dynamic arrays — provide flexibility and memory effi-
ciency.
Page 4
SystemVerilog Interview Collection VeriCore Academy
• Queues grow and shrink with push front(), push back(), pop front(), pop back().
Syntax:
initial begin
q.push_back(10); // Add to end
q.push_front(5); // Add to start
q.pop_back(); // Remove last element
end
Use Case: Queues are ideal for modeling FIFOs or temporary transaction buffers.
Page 5
SystemVerilog Interview Collection VeriCore Academy
Q5. What are associative arrays in SV? Where are they best
used?
Answer: Associative arrays allow indexing using any scalar data type, not just integers.
They’re best when the index is sparse or unknown at compile time.
Syntax:
initial begin
aa["read"] = 1;
aa["write"] = 0;
end
Features:
• Dynamic memory
Page 6
SystemVerilog Interview Collection VeriCore Academy
• first(var)
• last(var)
• next(var)
• prev(var)
Example:
initial begin
aa["a"] = 1;
aa["b"] = 2;
aa["c"] = 3;
key = aa.first();
while (key != "") begin
$display("Key: %s, Value: %0d", key, aa[key]);
key = aa.next(key);
end
end
Page 7
SystemVerilog Interview Collection VeriCore Academy
• high(array) − U pperbound.
Example:
initial begin
$display("Size: %0d", $size(arr)); // Output: 5
$display("Left: %0d", $left(arr)); // Output: 5
$display("Right: %0d", $right(arr)); // Output: 1
$display("Low: %0d", $low(arr)); // Output: 1
$display("High: %0d", $high(arr)); // Output: 5
end
Page 8
SystemVerilog Interview Collection VeriCore Academy
initial begin
q = {1, 2, 3};
q.push_back(4);
q.pop_front();
q.pop_back();
end
Note: Use queues in scoreboards and transaction-level modeling for dynamic buffer-
ing.
Page 9
SystemVerilog Interview Collection VeriCore Academy
Usage:
Page 10
SystemVerilog Interview Collection VeriCore Academy
type’(bit_vector)
Example:
Advantage:
Page 11
SystemVerilog Interview Collection VeriCore Academy
• Shallow Copy: Copies handle only. Both variables point to the same memory.
• Deep Copy: Clones object and creates a new instance with same data.
class A;
int x;
endclass
A obj1 = new();
obj1.x = 10;
Page 12
SystemVerilog Interview Collection VeriCore Academy
int dyn_array[];
dyn_array = new[10]; // Allocates 10 elements
Class Array:
class Item;
int value;
endclass
Item items[];
initial begin
items = new[5];
foreach(items[i])
items[i] = new(); // Allocate each object
end
Page 13
SystemVerilog Interview Collection VeriCore Academy
int arr[5];
foreach (arr[i])
$display("Index: %0d, Value: %0d", i, arr[i]);
2D Example:
foreach (arr[i,j])
$display("arr[%0d][%0d]=%0d", i, j, arr[i][j]);
Page 14
SystemVerilog Interview Collection VeriCore Academy
Call:
int aa[string];
aa["apple"] = 1;
aa["banana"] = 2;
printAA(aa);
Page 15
SystemVerilog Interview Collection VeriCore Academy
Class:
class Packet;
rand bit [7:0] addr;
endclass
Interface:
interface bus_if;
logic clk, rst;
logic [7:0] data;
endinterface
Page 16
SystemVerilog Interview Collection VeriCore Academy
• randc: Generates random values in a cyclic fashion (without repetition until all
values are used).
Example:
class A;
rand bit [1:0] x; // can repeat
randc bit [1:0] y; // cycles through all values 0 to 3
endclass
Use Case: Use ‘randc‘ when you want exhaustive permutation, such as generating
all priority levels, IDs, etc.
Page 17
SystemVerilog Interview Collection VeriCore Academy
class Base;
rand bit [7:0] data;
constraint c1 { data < 100; }
endclass
Note: Constraint names must match exactly. Overridden constraints are evaluated
instead of the parent’s.
Page 18
SystemVerilog Interview Collection VeriCore Academy
if (!obj.randomize())
$error("Randomization Failed");
Debugging Tips:
Page 19
SystemVerilog Interview Collection VeriCore Academy
randcase
1: a = 1;
3: a = 2; // Higher weight, more likely
endcase
Use Case: Modeling probabilistic behaviors such as random traffic generation, error
injection, etc.
Page 20
SystemVerilog Interview Collection VeriCore Academy
class Animal;
function void speak();
$display("Generic Animal");
endfunction
endclass
Usage:
Page 21
SystemVerilog Interview Collection VeriCore Academy
Example:
Page 22
SystemVerilog Interview Collection VeriCore Academy
Instantiation:
Page 23
SystemVerilog Interview Collection VeriCore Academy
class C;
int x;
endclass
C obj = null;
$display(obj.x); // Fatal: null handle dereference
Prevention:
if (obj != null)
$display(obj.x);
Page 24
SystemVerilog Interview Collection VeriCore Academy
class Packet;
int data;
function new(Packet p);
this.data = p.data;
endfunction
endclass
Usage:
Packet p1 = new();
p1.data = 100;
Packet p2 = new(p1); // Copy constructor
Page 25
SystemVerilog Interview Collection VeriCore Academy
rand int x;
constraint c1 { x > 5; }
constraint c2 { x < 3; } // Conflicts with c1 → randomization fails
Page 26