Consider this Verilog code snippet for a simple flip-flop. What will be the value of q after the positive edge of clk?
module dff(input clk, input d, output reg q); always @(posedge clk) begin q <= d; end endmodule // Testbench snippet reg clk; reg d; initial begin clk = 0; d = 1; #5 clk = 1; // posedge #5 clk = 0; end
Remember that q updates only on the positive edge of clk.
The flip-flop updates q to the value of d only at the rising edge of clk. Since d is 1 at that time, q becomes 1.
In synthesis, why is it important to avoid unintended latches in combinational logic?
Think about how hardware behaves when signals are not fully specified.
Unintended latches hold their previous state when inputs are not fully specified, causing timing uncertainty and glitches. This makes the hardware unreliable.
What synthesis problem does this Verilog code cause?
module mux(input sel, input a, input b, output reg y); always @(*) begin if (sel == 1'b1) y = a; // Missing else branch end endmodule
Think about what happens to y when sel is 0.
Because y is not assigned in the else case, synthesis infers a latch to hold the previous value, which is usually unintended in combinational logic.
Which of the following Verilog code snippets will cause a syntax error during synthesis?
Check the module declaration and body syntax carefully.
Option D is missing the endmodule keyword properly and uses begin directly after module declaration without an always or initial block, causing a syntax error.
In Verilog, if a signal is driven by multiple always blocks or continuous assignments, what will synthesis typically do?
Think about hardware rules for signal driving and conflicts.
Multiple drivers on the same signal without explicit resolution cause conflicts. Synthesis tools usually report errors or generate unpredictable hardware, as real hardware cannot have multiple conflicting drivers on a single net.
