Professional Documents
Culture Documents
FALLSEM2021-22 ECE2003 ETH VL2021220100491 Reference Material V 22-09-2021 Task Function
FALLSEM2021-22 ECE2003 ETH VL2021220100491 Reference Material V 22-09-2021 Task Function
always @(P or Q)
begin
log_cal (PQ_AND, PQ_OR, PQ_XOR, P, Q);
end
Function properties
• Functions should not contain delay information.
• Functions must contain at least one input.
• Supports only input arguments.
• A function can call other function only.
function par_cal;
function <range><function_name>;
input [15:0]dat_in;
<function_declarations >
begin
input declarations;
par_cal = ^dat_in;
begin end
<assignments>
end endfunction
endfunction
Function calling
wire [15:0]data;
reg parity_value;
always @(enable)
begin
if (enable == 1’b1)
parity_value = par_cal(data);
end
Tasks and Functions
functions tasks
can enable other function, can enable other functions
not a task. and tasks.
execute in 0 simulation execute in non 0 simulation
time. time.
do not support delay, event can have delays, event or
or timing controls. timing controls.
must have at least one can have zero or more
input argument, can have arguments of type input,
more than one input. output or inout.
return single value , they do not return any value, but
can not have output or can pass multiple values
inout arguments. thro’ output and inout args.
When to use tasks ?
• Use tasks when:
– there are delay, timing, or event control constructs in
the procedure.
OR
– the procedure has zero or more than one output
arguments.
OR
– the procedure has no input arguments.
When to use functions ?