Digital System Design: Verilog HDL Tasks and Functions
Digital System Design: Verilog HDL Tasks and Functions
Verilog® HDL
Tasks and Functions
Maziar Goudarzi
Today program
Reusing code
Tasks and Functions
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
Functions
Tasks
Differences between tasks and functions
Semantics
much like function in Pascal
An internal implicit reg is declared inside the
function with the same name
The return value is specified by setting that
implicit reg
<range_or_type> defines width and type of the
implicit reg
<type> can be integer or real
default bit width is 1
2005 Verilog HDL 9
Function Examples
Parity Generator
module parity; function calc_parity;
reg [31:0] addr; input [31:0] address;
reg parity; begin
calc_parity = ^address;
initial begin end
… endfunction
end
endmodule
always @(addr)
begin
parity = calc_parity(addr);
$display("Parity calculated = %b",
calc_parity(addr) );
end
always @(addr)
begin
left_addr =shift(addr, `LEFT_SHIFT);
right_addr =shift(addr,`RIGHT_SHIFT);
2005 Verilog HDL 11
end
Tasks and Functions
Tasks
Tasks
task <task_name>;
<I/O declarations>
<variable and event declarations>
begin // if more than one statement needed
<statement(s)>
end // if begin used!
endtask
Homework 7
Chapter 8, all exercises
Due date: Next Sunday (Azar 20th)