08-Verilog Tasks and Functions
08-Verilog Tasks and Functions
Design
VERILOG® HDL
TASKS AND FUNCTIONS
Introduction
Procedures/Subroutines/Functions in SW programming languages
◦ The same functionality, in different places
Verilog equivalence:
◦ Tasks and Functions
◦ Used in behavioral modeling
◦ Part of design hierarchy Hierarchical name
always @(addr)
begin
left_addr =shift(addr, `LEFT_SHIFT);
right_addr =shift(addr,`RIGHT_SHIFT);
end
12/29/23 VERILOG HDL 8
//Define a factorial with a recursive
function // Call the function
module top; integer result;
... initial
// Define the function begin
function automatic integer factorial; result = factorial(4); // Call
input [31:0] oper; the factorial of 7
integer i; $display("Factorial of 4 is
begin %0d", result); //Displays 24
if (operand >= 2) end
factorial = factorial (oper -1) * oper; ...
//recursive call ...
else endmodule
factorial = 1 ;
end
endfunction
TASKS
Tasks
Keywords: task, endtask
Must be used if the procedure has
◦ any timing control constructs
◦ zero or more than one output arguments
◦ no input arguments
task <task_name>;
<I/O declarations>
<variable and event declarations>
begin // if more than one statement needed
<statement(s)>
end // if begin used!
endtask