vlsimodule4
vlsimodule4
Verilog makes a clear differentiation between tasks and functions. The most important difference is
that:
• A function:
o Must return a value, and the value must be used (e.g., in an assignment statement).
• If you have a SystemVerilog task that does not consume time, you should make it a void
function, which is a function that does not return a value.
• Benefits:
o Debug routines are better implemented as void functions for maximum flexibility.
endfunction
• In SystemVerilog, if you want to call a function and ignore its return value, cast the result to
void.
• Example:
• Some simulators, such as VCS, allow you to ignore the return value without using the void
syntax.
2.Explain with examples the various system verilog assertions
This excerpt introduces SystemVerilog Assertions (SVA), a powerful feature in SystemVerilog for
specifying and verifying design behavior. Below is a summary and key points covered in this text:
• Purpose: Assertions are used to verify that design signals meet specific conditions during
simulation.
• Types:
Immediate Assertions
1. Usage:
o Immediate assertions are compact and succinct compared to procedural code (if
statements).
o if (bus.cb.grant != 2'b01)
3. Optional Actions:
o grants_received++;
o else
o $error("Grant not asserted");
Concurrent Assertions
1. Purpose:
2. Specification:
o Example:
o property request_2state;
o endproperty
3. Highlights:
o Concurrent assertions check for relationships that span across multiple clock cycles.
o They are declarative, making them simpler than equivalent procedural code.
Explain the 1. Returning of array from a function 2. Passing an array to a function in system Verilog
One technique is to define a type for the array and use that in the function declaration. The
example below uses the array type from Sample 2.35 and creates a function to initialize the
array.
initial begin
f5 = init(5);
foreach (f5[i])
$display("f5[%0d] = %0d", i, f5[i]);
end
One issue with the preceding code is that the function init creates an array, which is copied
into the array f5. If the array is large, this could result in significant performance problems.
int fa[5];
initial begin
init(fa, 5);
foreach (fa[i])
$display("fa[%0d] = %0d", i, fa[i]);
end
By using a ref argument, the function modifies the array directly, avoiding the need to copy
large arrays and improving performance.