0% found this document useful (0 votes)
4 views2 pages

Vlsi 3 Ia

Uploaded by

sahilron9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Vlsi 3 Ia

Uploaded by

sahilron9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1) Explain tasks and void functions with examples

Tasks in SystemVerilog

A task in SystemVerilog is a block of code that executes multiple statements, can include delays, and can modify the
simulation state. Tasks do not return a value, and they can have input, output, and inout arguments. A task can also
contain control flow structures like if, case, loops, etc.

Example of a Task:

Explanation:

• The task simple_task multiplies the input a by 2 and assigns the


result to b.

• It is called in the initial block where x = 5 is passed to the task, and


the result is displayed.

Characteristics of Tasks:

• Can include delays, wait statements, or other time-related controls.

• Do not return a value; instead, output arguments are used to return


results.

• Can call other tasks or functions within them.

Void Functions in SystemVerilog

A void function is similar to a task but it does not return any value. A void function is defined with the void return
type, and it may perform computations or execute commands. Void functions do not have the ability to use time
delays or control flow related to time.

Example of a Void Function:

Explanation:

• The function simple_function takes an


integer input and prints it using $display.

• It does not return any value and simply


performs a task within the function body.

Characteristics of Void Functions:

• Cannot contain delays or time-related


constructs.

• Can be called to perform actions but will not


return any value.

• Do not use output or inout arguments since they don't return a value.

Key Differences Between Tasks and Void Functions:


Feature Task Void Function

Return Type Does not return a value Does not return a value (void)

Delays and
Can include delays (#) and wait Cannot include delays or wait
Time

Arguments Can have input, output, or inout arguments Can only have input arguments

Control Flow Supports control flow and time-related constructs Cannot use time-related constructs

Used for executing multiple statements with time Used for performing simple actions without
Purpose
control delays

Both tasks and void functions help to structure code in SystemVerilog, but they serve different purposes. Tasks are
better for operations that require time control, while void functions are useful for simpler actions without time
delays.

You might also like