Verilog Questions With Answer
Verilog Questions With Answer
Answers
1. Difference between blocking and non-blocking assignments
Blocking Assignments: The blocking assignment statements are executed
sequentially by evaluating the RHS operand and finishes the assignment to LHS
operand without any interruption from another Verilog statement. Hence, it blocks
other assignments until the current assignment completes and is named a
“blocking assignment”.
Ex: a = 5;
Non-Blocking Assignments: The non-blocking assignment statement starts its
execution by evaluating the RHS operand at the beginning of a time slot and
schedules its update to the LHS operand at the end of a time slot. Other Verilog
statements can be executed between the evaluation of the RHS operand and the
update of the LHS operand. As it does not block other Verilog statement
assignments, it is called a non-blocking assignment.
Ex: a <= 5;
1. The net (wire, tri) is used for physical connection between structural elements.
3. It can not store any value. The values can be either read or assigned.
4. Default value – z
Register type:
1. The register (reg, integer, time, real, real-time) represents an abstract data
storage element and they are not the physical registers.
4. Default value – x
The regular delay control delays the execution of the entire statement by a
specified value. The non-zero delay is specified at the LHS of the procedural
statement.
In a full case statement, case statements cover every possible input value is
explicitly specified and there are no unspecified or “don’t care” conditions.
Example:
case (input)
3'b000: ………
3'b001: ………
3'b010: ………
3'b011: ………
3'b100: ………
3'b101: ………
3'b110: ………
3'b110: ………
default: // any other input case which is not covered
endcase
Parallel Case:
In a parallel case statement, multiple case items can match the input value
simultaneously and the corresponding behaviors for that will be executed in
parallel.
Example:
9. What is synchronous and asynchronous reset? Can you explain using DFF
and write their Verilog code?
In asynchronous reset, a flip flop gets reset as soon as the ‘reset’ signal is
asserted. Thus, in Verilog implementation, the ‘reset’ signal has to be written in the
sensitivity list of always block.
In synchronous reset, a flip flop gets reset at the active ‘clock’ edge when the
‘reset’ signal is asserted.
Thus, in Verilog implementation, the ‘reset’ signal must not be written in the
sensitivity list of the always block.
Without zero delay control, the ‘data’ variable may have a value of either 2 or 3
due to race conditions. Having zero delay statements as specified in the above
code guarantees the outcome to be 3. However, it is not recommended to assign
value to the variable at the same simulation time.
module tb;
bit clk1, clk2;
initial forever #5ns clk1 = ~clk1;
initial forever #4ns clk2 = ~clk2;
endmodule
The process of converting hardware description language like Verilog code into
the equivalent netlist design that has flip-flops, logic gates, and required digital
circuit components.
module clk_gen;
realtime on_t = `CLK_PERIOD * 0.6;
realtime off_t = `CLK_PERIOD * 0.4;
bit clk;
always begin
#on_t clk = 0;
#off_t clk = 1;
end
initial begin
clk = 1;
#50 $finish;
end
initial begin
// Dump waves
$dumpfile("dump.vcd");
$dumpvars(0);
end
endmodule
With a 50% duty cycle, clock has to flip a bit after every 5ns.
module clk_gen;
reg clk;
always #5 clk = ~clk;
endmodule
For a need basic, we can use the ‘forever’ loop as a work-around with a ‘break’
statement to terminate the loop as per requirement.
18. What is FIFO? What are underflow and overflow conditions in FIFO? Write
Verilog code for the design.
always@(*) begin
if(en) begin
data <= 8‘hFF;
end
end
22. What is infer latch means? How can you avoid it?
Infer latch means creating a feedback loop from the output back to the input due
to missing if-else condition or missing ‘default’ in a ‘case’ statement.
Infer latch indicates that the design might not be implemented as intended and
can result in race conditions and timing issues.
How to avoid it?
2. Using defparam
It has two separate ports for It has one end for writing into the
Access
read/write simultaneous access. FIFO and another end for reading.
e.g A = 3’b1x0
B = 3’b10x
A == B will give X as output.
28. Write A Verilog Code To Swap the Contents Of Two Registers With And
Without A Temporary Register?
With temp reg ;
The sensitivity list indicates that when a change occurs to any one of the elements
in the list change, the begin…end statement inside that always block will get
30. What Is The Difference Between The Following Lines Of Verilog Code?
#5 a = b;
a = #5 b;
#5 a = b;