Examine the two recursive/concurrent factorial implementations: // Module…
Examine the two recursive/concurrent factorial implementations: // Module A module task_static_demo; task compute_fact; input integer n; output integer result; begin if (n > 1) begin compute_fact(n - 1, result); result = n * result; end else begin result = 1; end end endtask endmodule // Module B module task_auto_demo; task automatic compute_fact; input integer n; output integer result; begin if (n > 1) begin compute_fact(n - 1, result); result = n * result; end else begin result = 1; end end endtask endmodule Which of the following statements are **TRUE** regarding synthesis, simulation, and memory allocation of tasks and functions in Verilog? *(Select all that apply)*
- In task_static_demo , calling compute_fact(4, res) fails to return the mathematical factorial ($24$) because n and result share single, static memory storage across recursive calls.
- Tasks declared as automatic allocate inputs, outputs, and local variables dynamically on a call stack, allowing re-entrancy and proper recursion in simulation.
- Verilog-2001 logic synthesis tools can synthesize recursive automatic tasks into hardware loops by statically unrolling them if the termination bound is a compile-time constant.
- A standard Verilog function can contain intra-assignment delays ( #5 ), non-blocking assignments ( <= ), and can invoke a task .
- A task can enable another task and contain timing control statements ( @ , # ), whereas a function executes in zero simulation time and cannot contain delays or timing controls.
Correct answer
A. In task_static_demo , calling compute_fact(4, res) fails to return the mathematical factorial ($24$) because n and result share single, static memory storage across recursive calls.; B. Tasks declared as automatic allocate inputs, outputs, and local variables dynamically on a call stack, allowing re-entrancy and proper recursion in simulation.; E. A task can enable another task and contain timing control statements ( @ , # ), whereas a function executes in zero simulation time and cannot contain delays or timing controls.
Explanation
* **A is TRUE:** In traditional Verilog, task inputs, outputs, and internal registers are statically allocated at a single fixed memory location. Recursive calls overwrite n and result on the same static address space, corrupting the return chain. * **B is TRUE:** The automatic keyword (introduced in Verilog-2001) forces stack-frame allocation per call, making tasks and functions re-entrant and thread-safe across concurrent/recursive invocations. * **C is FALSE:** Logic synthesis tools strictly prohibit recursive task/function definitions, even if declared automatic with constant boundaries. Loop unrolling only applies to for loops inside generate blocks or synthesizable procedural loops. * **D is FALSE:** Functions cannot contain timing controls ( # , @ , wait ), cannot make non-blocking assignments, and cannot call tasks (unless the task contains no timing delays, but synthesizable standard rules forbid functions calling tasks entirely). * **E is TRUE:** Tasks permit procedural delays and can invoke other tasks or functions; functions strictly enforce zero-delay combinatorial evaluation.