Recall & Review
beginner
What is the purpose of an
always block in Verilog?An
always block is used to describe behavior that should happen whenever certain signals change. It helps model sequential or combinational logic by running the code inside whenever the specified signals in the sensitivity list change.Click to reveal answer
beginner
How does an
if-else statement work inside an always block?Inside an
always block, an if-else statement checks a condition and executes one block of code if the condition is true, and another block if it is false. This helps decide which signals to assign based on conditions.Click to reveal answer
intermediate
Why should you use non-blocking assignments (
<=) inside sequential always blocks?Non-blocking assignments (
<=) allow all assignments to happen in parallel at the end of the time step, which models real hardware registers correctly and avoids race conditions.Click to reveal answer
intermediate
What happens if you forget the
else part in an if-else inside an always block?If you omit the
else, the signal might keep its old value unintentionally, causing inferred latches or unexpected behavior in hardware.Click to reveal answer
beginner
Example: What does this code do?<br>
always @(posedge clk) begin if (reset) count <= 0; else count <= count + 1; end
This code resets the
count to 0 when reset is true at the rising edge of clk. Otherwise, it increments count by 1 on each clock cycle.Click to reveal answer
In Verilog, which keyword starts a block that runs whenever signals change?
✗ Incorrect
The
always block runs its code whenever signals in its sensitivity list change.Inside an
always block, what does an if-else statement do?✗ Incorrect
An
if-else checks a condition and runs code based on whether it is true or false.Which assignment operator models registers correctly inside a clocked
always block?✗ Incorrect
Non-blocking assignments (
<=) model registers by updating all values simultaneously at the end of the time step.What risk do you face if you omit the
else in an if-else inside an always block?✗ Incorrect
Omitting
else can cause inferred latches, which means the hardware remembers old values unexpectedly.What does this code do?<br>
always @(posedge clk) begin if (reset) count <= 0; else count <= count + 1; end
✗ Incorrect
The code resets
count to 0 when reset is true, otherwise increments it on each clock rising edge.Explain how an if-else statement inside an always block controls signal assignments in Verilog.
Think about how hardware decides what value to hold based on conditions.
You got /4 concepts.
Describe why non-blocking assignments are preferred inside clocked always blocks with if-else statements.
Consider how hardware registers update all at once on a clock edge.
You got /4 concepts.