HDL & Verification

Which coding style is commonly used to prevent unintended latches in combinational always blocks?

  1. AWrite as many branches as possible and omit else
  2. BAssign default values to every output signal at the top of the block before the conditional logic
  3. CDeclare all outputs as wire and assign them inside always
Show answer and explanation

Answer: B. Assign default values to every output signal at the top of the block before the conditional logic

Putting defaults such as "y = 0; valid = 0;" at the top ensures every output is assigned at least its default on whatever path the later branches take, so nothing needs to hold its value and no latch forms. This is especially helpful for state machine outputs with many conditions. With SystemVerilog's always_comb, tools also warn if a latch is inferred.

  • A. Omitting else causes latches.
  • B. Correct. Every path then assigns a value.
  • C. A wire cannot be assigned in an always block.

Related calculators

Books on HDL & Verification Ad

As an Amazon Associate I earn from qualifying purchases.

More HDL & Verification questions

  1. Which Verilog construct is ignored by logic synthesis and does not become hardware (a simulation-only construct)?
  2. When the code above, which counts the 1s in 8-bit d, is synthesized, what kind of circuit results?
  3. What type of reset does the code above have, and how does it behave?
  4. What is the difference between synchronous and asynchronous resets?
  5. In circuits using an active-low asynchronous reset (rst_n), why is reset release (the 0-to-1 transition) synchronized to the clock through two flip-flops before distribution?

Comparisons in this topic