0
0
Verilogprogramming~10 mins

Latch inference and how to avoid it in Verilog - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to avoid latch inference by assigning a default value.

Verilog
always @(*) begin
  if (enable) begin
    out = in;
  end else begin
    out = [1];
  end
end
Drag options to blanks, or click blank then click option'
A1'bz
B1'b0
Cenable
Din
Attempts:
3 left
💡 Hint
Common Mistakes
Not assigning 'out' in all branches causing latch inference.
Assigning 'out' only when 'enable' is true.
2fill in blank
medium

Complete the sensitivity list to properly infer combinational logic.

Verilog
always @([1]) begin
  if (sel) out = a;
  else out = b;
end
Drag options to blanks, or click blank then click option'
Aa or b
Bposedge clk
Cnegedge reset
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using clock edges in combinational always blocks.
Listing only some inputs causing incomplete sensitivity.
3fill in blank
hard

Fix the error in the code to avoid latch inference by completing the missing assignment.

Verilog
always @(*) begin
  case(sel)
    2'b00: out = a;
    2'b01: out = b;
    2'b10: out = c;
    // Missing default assignment
    [1]
  endcase
end
Drag options to blanks, or click blank then click option'
Adefault: out = 1'b0;
Bdefault: out = out;
Cdefault: out = a;
Ddefault: out = 1'bz;
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the default case causing inferred latches.
Assigning 'out' to itself in default case which does not prevent latches.
4fill in blank
hard

Fill both blanks to complete the code that avoids latch inference by assigning default values and using a complete sensitivity list.

Verilog
always @([1]) begin
  out = 1'b0; // default assignment
  if (enable) begin
    out = [2];
  end
end
Drag options to blanks, or click blank then click option'
A*
Bin
Cenable
Dclk
Attempts:
3 left
💡 Hint
Common Mistakes
Using clock edges in combinational always blocks.
Not assigning default value before conditional assignment.
5fill in blank
hard

Fill both blanks to complete the code that avoids latch inference by assigning default values, using a complete sensitivity list, and including a default case.

Verilog
always @([1]) begin
  out = 1'b0; // default assignment
  case(sel)
    2'b00: out = a;
    2'b01: out = b;
    2'b10: out = c;
    [2]: out = 1'b0;
  endcase
end
Drag options to blanks, or click blank then click option'
A*
Bdefault
C2'b11
Dposedge clk
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting default case causing latch inference.
Using clock edge sensitivity in combinational block.