Most programming languages usually use tasks and
functions to execute common procedures from different places in a
description. Considering the analogy of FORTRAN, tasks are similar to
subroutines and functions are similar to function. Verilog provides
tasks and functions to break up large behavioral designs into smaller
pieces. Tasks and functions allow a designer to abstract Verilog
codes that is used at many places in the design.
Tasks have input, output, and inout arguments;
functions have input arguments. Thus, values can be passed into and
out from tasks and functions.
Differences of Tasks and Functions
Tasks and functions serve different purpose in
Verilog, and the following table describes differences between tasks and functions in Verilog.
Functions | Tasks |
---|---|
can enable another function but not another task | can call or enable other tasks and functions |
always execute in 0 simulation time | may execute in non-zero simulation time |
must not contain delay, event, or timing control statements | may contain delay, event, wait or timing control statements |
must have at least 1 input argument, or many inputs | may have no or more arguments of type input, output, or inout |
always return a single value, cannot have output or inout arguments | do not return a value, but can pass multiple values through output and inout arguments |