Menu
Coddy logo textTech

Defaults Prevent Latches

Part of the RTL Design & Verification section of Coddy's Verilog journey. Lesson 1 of 38.

A combinational output must be assigned for every input path. If an always block skips assigning an output, that output retains its old value, which can infer a latch. A default assignment followed by overrides makes coverage visible.

Relevant excerpt; surrounding declarations and connections are supplied in the challenge.

always @* begin
    y = 0;
    if (en) y = data;
end

The default covers the disabled path, so the output depends only on current inputs.

Assign every combinational output on every path; use defaults before conditional overrides.

challenge icon

Challenge

Medium

Implement a gated 8-bit output: when en is one, y equals a; otherwise y is zero. Assign y on every combinational path. Output columns: y. All stimulus values are known binary values.

Complete design.v and preserve its module names and ports. The locked testbench.v supplies input changes and prints the outputs after they settle. It chooses a scenario using a simulator argument such as +CASE=1; no standard input is required. Do not add printing, delays or simulation termination to the design. Expected output is one row of decimal values per observation, separated by one space and ending with a newline.

Try it yourself

module dut (input en, input [7:0] a, output reg [7:0] y);
    // Replace this placeholder with your design.
    initial y = 0;
endmodule
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in RTL Design & Verification

Practice on your own: Online Verilog compiler