Igital Erification Low: Ahmoud Aeed Lbosily, Taff Erification Ngineer
Igital Erification Low: Ahmoud Aeed Lbosily, Taff Erification Ngineer
▪ Tasks and functions are building blocks of design and verification logic.
▪ They allow for modular and reusable development of code.
▪ They provide the ability to execute common procedures from several places in your logic.
▪ You can parameterize tasks and functions so that they can be invoked from different
places in your code with different parameters.
SystemVerilog functions:
▪ A function cannot have the following operators:
#, ##, @, fork join, fork join_any, wait, wait_order or expect
▪ A statements that do not block are allowed. For example, non-blocking assignments, named event trigger, and
fork join_none are allowed.
▪ A function’s primary purpose is to return a value that is to be used in an expression.
▪ May or may not take arguments.
▪ Here is the syntax in its simplest form:
. function <automatic | static> <data_type_or_implicit_or_void> function_name ( <arguments> );
. function_body
. endfunction
SystemVerilog functions:
function logic [63:0] add_int (int a, int b);
▪ The 1st and 2nd syntax are the same.
endfunction
▪ The function declarations default to the formal direction
“input”.
function logic [63:0] add_int;
▪ Once a direction is given, the subsequent formals default input int a;
input int b;
to the same direction. For example:
endfunction
function logic [2:0] getVal (int a, int b, output logic [2:0] x, y);
SystemVerilog functions:
§ In this example, “a” and “b” are inputs, “c” is inout, and “x” and “y” are outputs.
§ input is the copy value input at the beginning.
§ output is the copy value at the end of the function.
§ inout is the copy input at the beginning and output at the end.
§ Each formal argument has a data type that can be explicitly specified or inherited from the
previous argument. The default data type is “logic”.
function logic [2:0] getVal (int a, int b, inout
c, output logic [2:0] x, y);
Void functions:
§ Void functions do not return a value.
§ They simply execute statements within the function body.
§ For example:
The typical answer is YES. Let’s talk about this point when we discuss:
OOP/
SV Class
Mahmoud Elbosily, Confidential to ITI Students Year 2023 9/30/2023 21
Thank You!