Verilog tasks and functions

TASKS

      task task_name;

      ....

      endtask


FUNCTIONS

        function function_name;

        .....

        endfunction      

               
Differences between tasks and functions
  • A task can call another task and function, where as function can call only another function.
  • Task supports timing controlled constructs, where as functions will not.
  • Tasks can have one or more arguments of type input, output or inout whereas functions must have arguments of type input. Functions wouldn't support output & inout.
  • Tasks support both blocking & non blocking assignments where as functions support only blocking assignment.
  • Tasks can infer both combinational & sequential logic where as functions infer only combinational logic.
  • Functions will return a single value where as tasks can have output and inout arguments to return a value.