|
|
|
|
|
|
|
|
|
|
|
|
Introduction
|
|
|
Vera supports two means of encapsulating program fragments, functions and tasks. All functions and tasks are re-entrant and therefore can be called recursively. Subroutines must be declared at the top level or inside a class. Subroutine declarations cannot be nested. |
|
|
|
|
|
Function and Task can be terminated before full execution by executing "return" statement in anywhere in body of task or function. |
|
|
|
|
|
|
|
|
|
|
|
Function
|
|
|
Functions are provided for implementing operations containing arguments passed to the function and one return value. |
|
|
|
|
|
function data_type function_name (argument_list) {
statements;
}
|
|
|
|
|
|
Functions can return values of any valid data type as well as data structures. The return value must be of the data type defined in the function. To set the return value, assign a value to the name of the function within the body of the function. |
|
|
|
|
|
By default, functions declared at the top level have a global scope. The local keyword is used to reduce the scope of a function to the file in which the function is declared. |
|
|
|
|
|
Example : Function
|
|
|
|
|
|
1 program function_ex {
2 printf("Return Value %b\n",get_data(random(),random()));
3 {
4 bit [7:0] data = get_data(random(),random());
5 printf("Return Value %b\n", data);
6 }
7 }
8
9 // Some random function
10 function bit [7:0] get_data (bit [7:0] d1, bit [7:0] d2) {
11 printf("Value 1 %x, Value 2 %x\n",d1,d2);
12 get_data = (d1 + d2) | (d1 - d2);
13 }
You could download file function_ex.vr here
|
|
|
|
|
|
Simulation : Function
|
|
|
|
|
|
Value 1 ac, Value 2 1d
Return Value 11001111
Value 1 bf, Value 2 c9
Return Value 11111110
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|