Functions Functions are declared with the keywords function and endfunction. Functions are used if all of the following conditions are true for the procedure | Functions Functions are declared with the keywords function and endfunction. Functions are used if all of the following conditions are true for the procedure There are no delay timing or event control constructs in the procedure. The procedure returns a single value. There is at least one input argument. There are no output or inout arguments. There are no nonblocking assignments. Function Declaration and Invocation The syntax for functions is follows Example 8-6 Syntax for Functions function_declaration function automatic signed range_or_type function_identifier function_item_declaration function_item_declaration function_statement endfunction function automatic signed range_or_type function_identifier function_port_list block_item_declaration block_item_declaration function_statement endfunction function_item_declaration block_item_declaration tf_input_declaration function_port_list attribute_instance tf_input_declaration attribute_instance tf_input_declaration range_or_type range integer real realtime time There are some peculiarities of functions. When a function is declared a register with name function_identifer is declared implicitly inside Verilog. The output of a function is passed back by setting the value of the register function_identifer appropriately. The function is invoked by specifying function name and input arguments. At the end of function execution the return value is placed where the function was invoked. The optional range_or_type specifies the width of the internal register. If no range or type is specified the default bit width is 1. Functions are very similar to FUNCTION in FORTRAN. Notice that at least one input argument must be defined for a function. There are no output arguments for functions because the implicit register function_identifer contains the output value. Also functions cannot invoke other tasks. They can invoke only other functions. Function Examples We will discuss two examples. The first example models a