top of page

15.3. Static and Automatic Behavior

​

The storage allocation for task and function variables can be either static (default) or automatic. This determines the lifetime and sharing of local variables.

​

15.3.1. Static Tasks/Functions (Default)

​

In static tasks/functions, local variables are allocated once and shared across all invocations. They retain their values between calls.

​

Characteristics

​

  • Variables allocated ONCE at elaboration

​

  • All calls share the SAME storage

​

  • Values retained between calls

​

  • NOT re-entrant safe

​

  • Default behavior

​

Example

Verilog

15.3.2. Automatic Tasks/Functions

​

In automatic tasks/functions, local variables are allocated dynamically for each call. Each invocation gets its own storage space.

​

Characteristics

​

  • Variables allocated on EACH call

​

  • Each call has SEPARATE storage

​

  • Values NOT retained between calls

​

  • RE-ENTRANT safe

​

  • Required for recursion

​

  • Must use 'automatic' keyword

​

Syntax

Verilog

Example - Recursive Factorial

Verilog

15.3.3. Comparison: Static vs Automatic

Screenshot (767).png

Task

Re-entrant Task & function
 

© Copyright 2025 VLSI Mentor. All Rights Reserved.©

Connect with us

  • Instagram
  • Facebook
  • Twitter
  • LinkedIn
  • YouTube
bottom of page