The function can return the value and task cannot return the value.
What is the return value?
The user called the method, it will execute lines of code.
On completion of method definition method return some value.
On completion of method definition method return some value.
How can the function return value?
The return type should be mention in the function definition. Need to use of return keyword.
What is advantage/application to return value?
Many times a user needs to use the same condition multiple times.
Can function return 'x' or 'z'?
- Yes, function can return 'x' or 'z', need to use logic return type in function.
- Yes, function can return 'x' or 'z', need to use logic return type in function.
What is preferable task or function?
- Depends on the application user will decide to use task or function.
USER WANT CODE:
function logic hello(bit x);
$display("This is Hello function");
if(x == 1)
begin
return 1'hz; // return 'z' or 'x' state
end
endfunction
task Hi();
//##1;
int a;
a = 1;
$display("This is Hi task");
hello(a);
endtask
module top();
logic a;
initial
begin
Hi();
a = 1;
if(hello(a) === 1'hz) // '===' require for z or x comparison
begin
$display("I am good");
end
else
begin
$display("Good bye");
end
end
endmodule