System Verilog - Interview
System Verilog - Interview
System Verilog - Interview
reg and wire are two data types that existed from Verilog, while logic is a
new data type that was introduced in SystemVerilog.
1) A wire is a data type that can model physical wires to connect two
elements.
Wires can only be driven by continuous assignment statement and cannot
hold onto value if not driven. Wires can hence only be used to model
combinational logic.
2) A reg is a data type that can model a storage element or a state. They
need to be driven by an always block and cannot be driven by continuous
assignment
statement. A reg can be used to model both sequential and combinational
logic
3) A logic is a new data type in SystemVerilog that can be used to model
both
wires and state information (reg). It also is a 4 state variable and hence can
hold 0, 1, x and z values. If a wire is declared as a logic (wire logic), then it
can be used to model multiple drivers and the last assignment will take the
value.
What is the difference between a bit and logic data type?
bit is a 2-state data type that can take only values 0 and 1, while logic is a
4-state data type which can take values 0, 1, x, and z. 2-state variables will
help in a small simulation speed up but should not be used if it is used to
drive or sample signals from RTL design in which uninitialized and
unknown
values will be missed.
What is the difference between logic[7:0] and byte variable in SystemVerilog?
byte is a signed variable which means it can only be used to count values
till 127. A logic [7:0] variable can be used for an unsigned 8 bit variable that
can count up to 255.
Which of the array types: dynamic array or associative array, are good to
model really large arrays, say: a huge memory array of 64KB?
Associative arrays are better to model large arrays as memory is allocated
only when an entry is written into the array. Dynamic arrays on the other
hand need memory to be allocated and initialized before using.
For example: If you want a memory array of 64KB to be modelled using
dynamic array, you would first need to allocate 64K entries and use the
array for read/write. Associative arrays doesn’t need allocation and
initialization of memory upfront and can be allocated and initialized just
when an entry of the 64K array needs to be referenced. However,
associative arrays are also slowest as they internally implement search for
elements in the array using a hash.
Suppose a dynamic array of integers ( values ) is initialized to values as shown
below. Write a code to find all elements greater than 3 in the array using
array locator method “ find ”?
struct packed {
int a;
short int b;
byte c;
} pack1_s;
An unpacked struct need not be packed into contiguous set of bits and
hence different members could be placed in memory with gaps. Following
is an example with a structure having different data types that cannot be
packed in memory.
struct record {
string name;
int age;
string parent;
} record_s
Which of the following statement is true?
1) Functions should execute in Zero Simulation Time.
2) Tasks should execute in Zero Simulation Time.
Given a dynamic array of size 100, how can the array be re-sized to hold 200
elements while the lower 100 elements are preserved as original?
A dynamic array needs memory allocation using new[] to hold elements.
Here is an example with an integer array that grows from an initial size of
100 elements to 200
elements.
integer addr[]; // Declare the dynamic array.
addr = new[100]; // Create a 100-element array.
………
// Double the array size, preserving previous values.
addr = new[200](addr);
What is the difference between “forever” and “for” in SystemVerilog ?
The “forever” loop repeatedly executes a statement without any limit. The
only way execution can stop is by using a break statement. A forever loop if
used without any timing controls (like clock or time delay) can result in a
zero-delay infinite loop and cause hang in simulation. The “for” loop is used
for executing a statement for a defined number of times based on
conditions that are defined.
What is the difference between “case”, “casex” and “casez” in
SystemVerilog?
The case statement is a multiway decision statement that tests whether an
expression matches one of a number of possible values and branches
accordingly. Following is a
simple example to implement a 3:1 MUX using a case statement
case (select[1:0])
2’b00: out_sig = in0;
2’b01: out_sig = in1;
2’b10: out_sig = in2;
default: out_sig = ‘x
endcase
In the above example of using a “case” statement, the expression match
happens exactly with what is specified. For example, in above case
statement, if at least one of the select lines is X or Z, then it will not match
any conditions and will execute the default statement.
“ casez ” is a special version of case expression which allows don’t cares in
comparison of the expressions. These are typically useful in decoder logic
which only treats fewer bits. Here is an example where a 3 bit interrupt
request queue (irq) bus is decoded into 3 separate interrupt pins based on
which bit in the bus is high, while other bits are don’t
care.
casez (irq)
3’b1?? : int2 = 1’b1;
3’b?1? : int1 = 1’b1;
3’b??1 : int0 = 1’b1;
Endcase
“casex” is another special version where in addition to don’t cares, it also
ignores X and Z values in comparison.
Which of the logical equality operators “==” or “===” are used in case
expression conditions for case, casex, and casez?
All of the 3 case statements use “===” logical equality comparison to
evaluate condition matches.
What is the difference between $display, $write, $monitor and $strobe in
SystemVerilog?
1) $display : Print the values immediately when executed.
2) $strobe : Print the values at the end of the current timestep.
3) $monitor : Print the values at the end of the current timestep if any
values
change. If $monitor is called more than once, the last call will override
previous
one.
4)$write : This is same as $display but doesn’t terminate with a newline
(\n).
(30)Without using randomize method or rand,generate an array of unique values?
Ans:-
...
int UniqVal[10];
foreach(UniqVal[i]) UniqVal[i] = i;
UniqVal.shuffle();
...
1. Program blocks can't have always block inside them, modules can have.
2. Program blocks can't contain UDP, modules, or other instance of program block inside them. Modules don't
have any such restrictions.
3. Inside a program block, program variable can only be assigned using blocking assignment and non-program
variables can only be assigned using non-blocking assignments. No such restrictions on module
4. Program blocks get executed in the re-active region of scheduling queue, module blocks get executed in the
active region
5. A program can call a task or function in modules or other programs. But a module can not call a task or
function in a program.
More details:-
1. http://www.testbench.in/SV_24_PROGRAM_BLOCK.html
2. http://www.project-veripage.com/program_blocks_1.php and few more next/next !!!
3. Section 16, SystemVerilog LRM 3.1a ... It's worth the effort reading line-by-line (and between the lines if you
can :) ).
(37)What is the use of modports?
Ans:-
Modports are part of Interface. Modports are used for specifing the direction of the signals with respect to
various modules the interface connects to.
...
interface my_intf;
wire x, y, z;
modport master (input x, y, output z);
modport slave (output x, y, input z);
endinterface