Source – SV Verification Directory
Functions
- A function must return a value.
- A function should not include delays, event controls, or wait statements.
- A function can only contain inputs as arguments as it returns only one output value.
Similar to tasks:
- A function can be declared as automatic or static.
- It can contain static variables in automatic function and vice-versa.
Syntax: Function
function [return type] function_name (input_arguments);
// execute the code
return [value];
endfunction
Example Code: Function
module tb_function_ex;
function int mul_3(int x);
return x*3;
endfunction
initial begin
int x;
$display("---------- Multiply by 3 ----------");
repeat(20)begin
x = $urandom_range(1,9);
$display("x = %0d, mul_by_3 = %0d", x, mul_3(x));
end
end
endmodule