A designer uses a task inside an always @(*) block to decode a 2-bit cont…
A designer uses a task inside an always @(*) block to decode a 2-bit control signal: module task_synth_decoder ( input wire [1:0] sel, input wire [3:0] data_in, output reg [3:0] data_out ); task decode_apply; input [1:0] s; input [3:0] din; begin if (s == 2'b01) data_out = din; else if (s == 2'b10) data_out = ~din; // Note: 2'b00 and 2'b11 are not specified end endtask always @(*) begin decode_apply(sel, data_in); end endmodule What will the synthesis tool infer for data_out ?
- A 4-bit wide 4-to-1 multiplexer with zero-extended defaults.
- A 4-bit combinational transparent latch ($D$-latch) with sel decoded onto the latch enable ($EN$) pin.
- A set of 4 flip-flops triggered on any change in sel .
- A syntax error, because tasks cannot assign to module-level output reg signals directly.
Correct answer
B. A 4-bit combinational transparent latch ($D$-latch) with sel decoded onto the latch enable ($EN$) pin.
Explanation
1. In Verilog, a task shares the scope of the parent module and can directly read/write module-level variables (here, data_out ). 2. Inside decode_apply , data_out is assigned conditionally when s == 2'b01 and s == 2'b10 . However, when s == 2'b00 or s == 2'b11 , no assignment occurs to data_out . 3. Furthermore, always @(*) does not assign a pre-default fallback value to data_out before invoking the task. 4. Because the output is not fully specified for all combinations of the input conditions in a combinational procedural block, the synthesis tool must preserve the previous state of data_out whenever sel is 00 or 11 . 5. This infers a **transparent level-sensitive latch**, where the latch enable condition is: $EN = (sel == 2'b01) \lor (sel == 2'b10)$.