Advanced_VLSI_Modified_Presentation (1)
Advanced_VLSI_Modified_Presentation (1)
Advanced_VLSI_Modified_Presentation (1)
~SAI SAGAR S
P-
1RF21EC041
TABLE OF CONTENTS
2. Task overview
Routine Arguments:
Arguments are inputs or outputs for tasks or functions. They let data flow into
and out of routines, classified as input, output, or inout.
6. Default values
Tasks are similar to functions in other programming languages but are distinct
in that they can perform complex actions, including interactions with
simulation time, and can return multiple outputs through output or inout
arguments.
EXAMPLE:
task generate_clock_pulse(output bit clk);
clk = 1;
#5 clk = 0; // Delay for 5 time units
endtask
● Types of Tasks:
○ Non-blocking: Executes and allows the simulation to proceed concurrently.
○ Blocking: Pauses execution until the task is completed.
ROUTINE ARGUMENTS:
Routine Arguments:
Arguments are inputs or outputs for tasks or functions. They let data flow into
and out of routines, classified as input, output, or inout.
1. Input Arguments (`input`)
- Used to pass values into a routine.
- The value is received by the routine, but it cannot be modified within the
routine.
Routine Arguments:
Arguments are inputs or outputs for tasks or functions. They let data flow into
and out of routines, classified as input, output, or inout.
Arguments are specified in the routine header, and their data types must be
declared. SystemVerilog supports a variety of data types for routine
arguments, including basic types like `bit` and `logic`, as well as complex types
like arrays, structures, and classes.
- Functions can only have `input` arguments; they cannot have `output` or
SYNTAX FOR ROUTINE
ARGUMENTS
For tasks:
Example of Routine Argument
task my_task(input logic a, output int b, Usage
inout bit c);
// Task body
task compute_sum(input int a,
endtask input int b, output int sum, inout
int counter);
For functions: sum = a + b;
function int my_function(input int a, counter += 1; // Increment
input int b); counter each time the task is
called
// Function body
endtask
endfunction
Common Coding Errors:
Ensure each argument's type is clearly stated (e.g., input or output) to avoid
unexpected behavior.
To avoid sticky types, always declare both the direction (input, output,
inout, ref) and the data type explicitly for each argument in tasks and
functions. For example:
task my_task(input int a, input int b, input int c);
// Now, each argument has an explicit declaration.
endtask
Returning from Routines:
Functions can return a value directly, while tasks can end early with 'return' without giving
back a value.
Example:
function int calculate_sum(input int a, b);
if (a < 0 || b < 0) begin
return -1; // Return early if inputs are invalid
end
return a + b; // Return the sum
endfunction
Returning from Tasks:
● Tasks in SystemVerilog do not return values but may still use the
return statement to terminate execution early. This can be useful
in cases where the task encounters an error or when the required
operation is complete before the end of the task body.
task send_data(input bit[7:0] data);
if (data == 8'h00) begin
$display("Invalid data, aborting.");
return; // Exit the task early
end
// Continue with sending data...
endtask
Using Typedef for Arrays:
To return arrays from a function, it's best to use typedef to define the
array type. This simplifies the function definition and keeps your code
readable, especially when dealing with multi-dimensional or complex
arrays.
Using a default value of −1 (or any out-of-range value) is a good way to see if the
call specified a value.
A Verilog for loop always executes the initialization ( int i=low ), and test
( i<=high ) before starting the loop. Thus, if you accidentally passed a low value that
was larger than high or the array size, the for loop would never execute the body.
Passing Arguments by Name:
For tasks or functions with many arguments, specify only the ones
you
In theneed by naming
SystemVerilog them
LRM that explicitly.
the arguments to a task or function are
sometimes called “ports,” just like the connections for a module.
If you have a task or function with many arguments, some with default values,
and you only want to set a few of those arguments, you can specify a subset by
specifying the name of the routine argument with a port-like syntax, as shown