Tasks
  
    
    
     
   
   Formal Definition
  
   Tasks provide a means of splitting code into small parts. Often tasks 
   consist of frequently used functionalities. 
  
   Simplified Syntax
  
   task identifier; 
  
     parameter_declaration; 
  
     input_declaration; 
  
     output_declaration; 
  
     inout_declaration; 
  
     register_declaration; 
  
     event_declaration; 
  
     statement; 
  
   endtask 
  
   Description
  
   Task definition begins with the keyword task 
   and ends with the keyword endtask.
    A task should be followed by a task identifier and end with a 
   semicolon. A task can contain a declaration of parameters, input 
   arguments, output arguments, inout arguments, registers and events 
   (these declarations are similar to module items declaration) but they 
   are not required. Net declaration is illegal. 
  
   A task can contain zero or more behavioral statements, e.g. case 
   statement, if statement. A begin-end block is required for bracketing 
   multiple statements. 
  
   The task enabling statement should be made up of a task identifier 
   and the list of comma-separated task arguments. The list of task 
   arguments should be enclosed in parenthesis. If the task does not 
   contain any argument declarations, then it should be enabled by 
   specifying its identifier followed by a semicolon (Example
    2). 
  
   The list of task enabling arguments should correspond exactly to the 
   list of task arguments. If a task argument is declared as an input, 
   then a corresponding argument of the task enabling statement can be 
   any expression. If a task argument is declared as an output or an 
   inout then the corresponding argument of the task enabling statement 
   should be one of the following items: 
  
   - 
   
    Register data types 
    - 
   
    Memory references 
    - 
   
    Concatenations of registers or memory references 
    - 
   
    Bit-selects and part-selects of reg,
     integer and time registers 
     
  
   Only the last assignment to an output or an inout argument is passed 
   to the corresponding task enabling arguments. If a task has 
   assignments to global variables, then all changes of these variables 
   are effective immediately. 
  
   Tasks can enable others tasks (Example
    3) and functions. A task may be enabled several times in a 
   module. If one task is enabled concurrently, then all registers and 
   events declared in that task should be static, i.e., one variable for 
   all instances. 
  
   A task can contain time-controlling statements. A task does not 
   return a value by its name. 
  
   Examples
  Example 1 
  
   task first_task; 
     parameter size = 4; 
     input a; 
     integer a; 
     inout [size-1:0] b; 
     output c; 
     reg [size-1:0] d; 
     event e; 
     begin 
     d = b; 
     c = |d; 
     b = ~b; 
     if (!a) -> e; 
     end 
   endtask 
  
   This is an example of using parameters, input arguments, inout 
   arguments, output arguments, registers and events within tasks. The 
   'a' argument is declared as an input and as an integer data type. 
  
   'First_task' can be enabled as follows: 
  
   integer x; 
   reg a, b, y; 
   reg [3:0] z; 
   reg [7:0] w; 
   first_task(x, z, y); 
   first_task(x, w[7:4], w[1]); 
   first_task(1, {a, b, w[3], x[0]}, y); 
  
   When being enabled, the first argument of the 'first_task' should be 
   an integer data type expression, the second should be a 4-bit 
   register expression, and the last argument should be 1-bit register expression. 
  Example 2 
  
   reg a, b; 
   task my_task; // task definition 
   begin 
     a = 1'b1; 
     b = 1'bx; 
   end 
   endtask 
   my_task; // task enabling 
  
   If 'my_task' is enabled then it will change the value of global 
   variables 'a' and 'b'. 
  Example 3 
   
   task negation; 
     inout data; 
     data = ~data; 
   endtask 
     
   task my_nor; 
     input a, b; 
     output c; 
     begin 
     negation(a); 
     negation(b); 
     c = a & b; 
     end 
   endtask 
  
   The 'my_nor' task enables negation tasks. 
  
   Important Notes
  
  
    
 
    |