SlideShare una empresa de Scribd logo
1 de 8
ENGR. RASHID FARID CHISHTI
LECTURER, DEE, FET, IIUI
CHISHTI@IIU.EDU.PK
WEEK 13
TASK AND FUNCTIONS
FPGA Based System Design
Sunday, May 17, 2015
1
www.iiu.edu.pk
 In verilog task can be used to code functionality that is repeated multiple times in
a module.
 A task has input, output and inout and can have its local variables.
 All the variables defined in the module are also accessible in the task.
 The task must be defined in the same module using task and endtask keywords.
 To use a task in other modules, the task should be written in a separate file and
the file then should be included using an `include directive in these modules.
 The tasks are called from initial or always blocks or from other tasks in a
module.
 The task can contain any behavioral statements including timing control
statements. Like module instantiation, the order of input, output and inout
declarations in a task determines the order in which they must be mentioned for
calling.
 As tasks are called in a procedural block, the output must be of type reg , whereas
the inputs may be of type reg or wire.
 Verilog 2001 adds a keyword automatic to the task to define a reentrant task.
www.iiu.edu.pk Sunday, May 17, 2015
Task
2
// The following example designs a task FA and calls it in a loop four times to
// generate a 4 bit ripple carry adder:
module RCA( input [3:0] a, b, input c_in, output reg c_out, output reg [3:0] sum);
reg carry[4:0]; integer i;
task FA( input in1, in2, carry_in, output reg out, carry_out);
assign {carry_out, out} = in1 + in2 + carry_in;
endtask
always@* begin
carry[0] = c_in;
for( i=0; i<4 ; i=i+1)
begin FA(a[i], b[i], carry[i], sum[i], carry[i+1]); end
c_out = carry[4];
end
endmodule
www.iiu.edu.pk Sunday, May 17, 2015
Task
3
 Verilog function is in many respects like task as it also implements code that can
be called several times inside a module.
 A function is defined in the module using function and endfunction keywords.
 The function can compute only one output. To compute this output, the function
must have at least one input.
 The output must be assigned to an implicit variable bearing the name and range of
the function.
 The range of the output is also specified with the function declaration.
 A function in Verilog cannot use timing constructs like # or @ . A function can be
called from a procedural block or continuous assignment statement.
 It may also be called from other functions and tasks, whereas a function cannot
call a task. A reentrant function can be designed by adding the automatic
keyword.
 A simple example here writes a function to implement a 2:1 multiplexer and then
uses it three times to design a 4:1 multiplexer:
www.iiu.edu.pk Sunday, May 17, 2015
Functions
4
module MUX4to1( input [3:0] in, input [1:0] sel, output out);
wire out1, out2;
function MUX2to1;
input in1, in2; input select;
assign MUX2to1 select ? in2:in1;
endfunction
assign out1 = MUX2to1(in[0], in[1], sel[0]);
assign out2 = MUX2to1(in[2], in[3], sel[0]);
assign out = MUX2to1 (out1 ,out2, sel[1]);
endmodule
/* stimulus for testing the module MUX4to1 */
module testFunction;
reg [3:0] IN; reg [1:0] SEL; wire OUT;
MUX4to1 mux(IN, SEL, OUT);
initial begin
www.iiu.edu.pk Sunday, May 17, 2015
Functions
5
IN = 1; SEL = 0;
#5 IN = 7; SEL = 0;
#5 IN = 2; SEL = 1;
#5 IN = 4; SEL = 2;
#5 IN = 8; SEL = 3;
end
initial
$monitor ( $time, " %b %b %bn ", IN, SEL, OUT);
endmodule
www.iiu.edu.pk Sunday, May 17, 2015
Functions
6
Task
 A task can enable other tasks and functions.
 Tasks may execute in non-zero simulation time.
 Tasks may contain delay, event, or timing control statements.
 Tasks may have zero or more arguments of type input, output, or inout.
 Tasks do not return with a value, but can pass multiple values through output and
inout arguments.
Function
 A function can enable another function but not another task.
 Functions always execute in 0 simulation time.
 Functions must not contain any delay, event, or timing control statements.
 Functions must have at least one input argument. They can have more than one
input.
 Functions always return a single value. They cannot have output or inout
arguments.
www.iiu.edu.pk Sunday, May 17, 2015
Task and Function
7
Task
 Tasks are used for common Verilog code that contains delays, timing, event
constructs, or multiple output arguments.
 Tasks can have input, output, and inout arguments
Function
 Functions are used when common Verilog code is purely combinational, executes
in zero simulation time, and provides exactly one output. Functions are typically
used for conversions and commonly used calculations.
 Functions can have input arguments. In addition, they can have local variables,
registers, time variables, integers, real, or events.
Task and Function Similarities
 Both tasks and functions must be defined in a module and are local to the module.
 Tasks or functions cannot have wires.
 Tasks and functions contain behavioral statements only.
 Tasks and functions do not contain always or initial statements but are called from
always blocks, initial blocks, or other tasks and functions.
www.iiu.edu.pk Sunday, May 17, 2015
Task and Function
8

Más contenido relacionado

La actualidad más candente

Designing of 8 BIT Arithmetic and Logical Unit and implementing on Xilinx Ver...
Designing of 8 BIT Arithmetic and Logical Unit and implementing on Xilinx Ver...Designing of 8 BIT Arithmetic and Logical Unit and implementing on Xilinx Ver...
Designing of 8 BIT Arithmetic and Logical Unit and implementing on Xilinx Ver...Rahul Borthakur
 
Floating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGAFloating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGAAzhar Syed
 
Performance Analysis of Reversible 16 Bit ALU based on Novel Programmable Rev...
Performance Analysis of Reversible 16 Bit ALU based on Novel Programmable Rev...Performance Analysis of Reversible 16 Bit ALU based on Novel Programmable Rev...
Performance Analysis of Reversible 16 Bit ALU based on Novel Programmable Rev...IRJET Journal
 
SDR channelizer by sooraj
SDR channelizer by soorajSDR channelizer by sooraj
SDR channelizer by soorajsooraj yadav
 
Design and implementation of low power
Design and implementation of low powerDesign and implementation of low power
Design and implementation of low powerSurendra Bommavarapu
 
Reducing computational complexity of Mathematical functions using FPGA
Reducing computational complexity of Mathematical functions using FPGAReducing computational complexity of Mathematical functions using FPGA
Reducing computational complexity of Mathematical functions using FPGAnehagaur339
 
Digital Logic Circuits
Digital Logic CircuitsDigital Logic Circuits
Digital Logic Circuitssathish sak
 
Introduction to Gura Programming Language
Introduction to Gura Programming LanguageIntroduction to Gura Programming Language
Introduction to Gura Programming LanguageYutaka Saito
 
Design and Synthesis of Multiplexer based Universal Shift Register using Reve...
Design and Synthesis of Multiplexer based Universal Shift Register using Reve...Design and Synthesis of Multiplexer based Universal Shift Register using Reve...
Design and Synthesis of Multiplexer based Universal Shift Register using Reve...IOSRJVSP
 
Computer Organization And Architecture lab manual
Computer Organization And Architecture lab manualComputer Organization And Architecture lab manual
Computer Organization And Architecture lab manualNitesh Dubey
 
A review on reversible logic gates and their implementation
A review on reversible logic gates and their implementationA review on reversible logic gates and their implementation
A review on reversible logic gates and their implementationDebraj Maji
 
Verilog presentation final
Verilog presentation finalVerilog presentation final
Verilog presentation finalAnkur Gupta
 
Introduction to digital logic
Introduction to digital logicIntroduction to digital logic
Introduction to digital logicKamal Acharya
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functionsTAlha MAlik
 

La actualidad más candente (20)

Designing of 8 BIT Arithmetic and Logical Unit and implementing on Xilinx Ver...
Designing of 8 BIT Arithmetic and Logical Unit and implementing on Xilinx Ver...Designing of 8 BIT Arithmetic and Logical Unit and implementing on Xilinx Ver...
Designing of 8 BIT Arithmetic and Logical Unit and implementing on Xilinx Ver...
 
Floating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGAFloating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGA
 
8 Bit ALU
8 Bit ALU8 Bit ALU
8 Bit ALU
 
Performance Analysis of Reversible 16 Bit ALU based on Novel Programmable Rev...
Performance Analysis of Reversible 16 Bit ALU based on Novel Programmable Rev...Performance Analysis of Reversible 16 Bit ALU based on Novel Programmable Rev...
Performance Analysis of Reversible 16 Bit ALU based on Novel Programmable Rev...
 
Sci py india_conference_2019
Sci py india_conference_2019Sci py india_conference_2019
Sci py india_conference_2019
 
SDR channelizer by sooraj
SDR channelizer by soorajSDR channelizer by sooraj
SDR channelizer by sooraj
 
Design and implementation of low power
Design and implementation of low powerDesign and implementation of low power
Design and implementation of low power
 
Cadancesimulation
CadancesimulationCadancesimulation
Cadancesimulation
 
Computron príručka
Computron príručkaComputron príručka
Computron príručka
 
Reducing computational complexity of Mathematical functions using FPGA
Reducing computational complexity of Mathematical functions using FPGAReducing computational complexity of Mathematical functions using FPGA
Reducing computational complexity of Mathematical functions using FPGA
 
Verilog lab manual (ECAD and VLSI Lab)
Verilog lab manual (ECAD and VLSI Lab)Verilog lab manual (ECAD and VLSI Lab)
Verilog lab manual (ECAD and VLSI Lab)
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
Digital Logic Circuits
Digital Logic CircuitsDigital Logic Circuits
Digital Logic Circuits
 
Introduction to Gura Programming Language
Introduction to Gura Programming LanguageIntroduction to Gura Programming Language
Introduction to Gura Programming Language
 
Design and Synthesis of Multiplexer based Universal Shift Register using Reve...
Design and Synthesis of Multiplexer based Universal Shift Register using Reve...Design and Synthesis of Multiplexer based Universal Shift Register using Reve...
Design and Synthesis of Multiplexer based Universal Shift Register using Reve...
 
Computer Organization And Architecture lab manual
Computer Organization And Architecture lab manualComputer Organization And Architecture lab manual
Computer Organization And Architecture lab manual
 
A review on reversible logic gates and their implementation
A review on reversible logic gates and their implementationA review on reversible logic gates and their implementation
A review on reversible logic gates and their implementation
 
Verilog presentation final
Verilog presentation finalVerilog presentation final
Verilog presentation final
 
Introduction to digital logic
Introduction to digital logicIntroduction to digital logic
Introduction to digital logic
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
 

Similar a Fpga 13-task-and-functions

Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsRuth Marvin
 
Notes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and FunctionsNotes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and FunctionsJay Baxi
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSDr.YNM
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++ppd1961
 
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdfankit482504
 
Assic 13th Lecture
Assic 13th LectureAssic 13th Lecture
Assic 13th Lecturebabak danyal
 
System verilog important
System verilog importantSystem verilog important
System verilog importantelumalai7
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptxmiki304759
 
chapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfchapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfstudy material
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptAmanuelZewdie4
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2yndaravind
 
Functions part1
Functions part1Functions part1
Functions part1yndaravind
 
Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018Luciano Mammino
 
An Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprAn Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprPrabhavathi P
 

Similar a Fpga 13-task-and-functions (20)

Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_arguments
 
Notes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and FunctionsNotes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and Functions
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONS
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
 
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf
 
Assic 13th Lecture
Assic 13th LectureAssic 13th Lecture
Assic 13th Lecture
 
Verilog Tasks and functions
Verilog Tasks and functionsVerilog Tasks and functions
Verilog Tasks and functions
 
System verilog important
System verilog importantSystem verilog important
System verilog important
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
chapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfchapter-8-function-overloading.pdf
chapter-8-function-overloading.pdf
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
Python_UNIT-I.pptx
Python_UNIT-I.pptxPython_UNIT-I.pptx
Python_UNIT-I.pptx
 
Function
Function Function
Function
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 
Functions
FunctionsFunctions
Functions
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2
 
Functions part1
Functions part1Functions part1
Functions part1
 
Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018
 
An Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl pprAn Introductory course on Verilog HDL-Verilog hdl ppr
An Introductory course on Verilog HDL-Verilog hdl ppr
 
Function
FunctionFunction
Function
 

Más de Malik Tauqir Hasan

Fpga 10-bcd-to-excess-3-converter-manchester-encoding
Fpga 10-bcd-to-excess-3-converter-manchester-encodingFpga 10-bcd-to-excess-3-converter-manchester-encoding
Fpga 10-bcd-to-excess-3-converter-manchester-encodingMalik Tauqir Hasan
 
Fpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machineFpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machineMalik Tauqir Hasan
 
Fpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineFpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineMalik Tauqir Hasan
 
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adder
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adderFpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adder
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adderMalik Tauqir Hasan
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesMalik Tauqir Hasan
 

Más de Malik Tauqir Hasan (11)

Fpga 12-event-control
Fpga 12-event-controlFpga 12-event-control
Fpga 12-event-control
 
Fpga 10-bcd-to-excess-3-converter-manchester-encoding
Fpga 10-bcd-to-excess-3-converter-manchester-encodingFpga 10-bcd-to-excess-3-converter-manchester-encoding
Fpga 10-bcd-to-excess-3-converter-manchester-encoding
 
Fpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machineFpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machine
 
Fpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineFpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machine
 
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adder
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adderFpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adder
Fpga 07-port-rules-gate-delay-data-flow-carry-look-ahead-adder
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directives
 
Fpga 05-verilog-programming
Fpga 05-verilog-programmingFpga 05-verilog-programming
Fpga 05-verilog-programming
 
Fpga 04-verilog-programming
Fpga 04-verilog-programmingFpga 04-verilog-programming
Fpga 04-verilog-programming
 
Fpga 03-cpld-and-fpga
Fpga 03-cpld-and-fpgaFpga 03-cpld-and-fpga
Fpga 03-cpld-and-fpga
 
Fpga 02-memory-and-pl ds
Fpga 02-memory-and-pl dsFpga 02-memory-and-pl ds
Fpga 02-memory-and-pl ds
 
Fpga 01-digital-logic-design
Fpga 01-digital-logic-designFpga 01-digital-logic-design
Fpga 01-digital-logic-design
 

Último

RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作f3774p8b
 
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...Amil baba
 
Kwin - Trang Tải App Game Kwin68 Club Chính Thức
Kwin - Trang Tải App Game Kwin68 Club Chính ThứcKwin - Trang Tải App Game Kwin68 Club Chính Thức
Kwin - Trang Tải App Game Kwin68 Club Chính ThứcKwin68 Club
 
Computer Organization and Architecture 10th - William Stallings, Ch01.pdf
Computer Organization and Architecture 10th - William Stallings, Ch01.pdfComputer Organization and Architecture 10th - William Stallings, Ch01.pdf
Computer Organization and Architecture 10th - William Stallings, Ch01.pdfShahdAbdElsamea2
 
澳洲Deakin学位证,迪肯大学毕业证书1:1制作
澳洲Deakin学位证,迪肯大学毕业证书1:1制作澳洲Deakin学位证,迪肯大学毕业证书1:1制作
澳洲Deakin学位证,迪肯大学毕业证书1:1制作rpb5qxou
 
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作ss846v0c
 
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjekAIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjekpavan402055
 
Dubai Call Girls O525547819 Spring Break Fast Call Girls Dubai
Dubai Call Girls O525547819 Spring Break Fast Call Girls DubaiDubai Call Girls O525547819 Spring Break Fast Call Girls Dubai
Dubai Call Girls O525547819 Spring Break Fast Call Girls Dubaikojalkojal131
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...Amil Baba Dawood bangali
 

Último (9)

RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作
 
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...
Uae-NO1 Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Addres...
 
Kwin - Trang Tải App Game Kwin68 Club Chính Thức
Kwin - Trang Tải App Game Kwin68 Club Chính ThứcKwin - Trang Tải App Game Kwin68 Club Chính Thức
Kwin - Trang Tải App Game Kwin68 Club Chính Thức
 
Computer Organization and Architecture 10th - William Stallings, Ch01.pdf
Computer Organization and Architecture 10th - William Stallings, Ch01.pdfComputer Organization and Architecture 10th - William Stallings, Ch01.pdf
Computer Organization and Architecture 10th - William Stallings, Ch01.pdf
 
澳洲Deakin学位证,迪肯大学毕业证书1:1制作
澳洲Deakin学位证,迪肯大学毕业证书1:1制作澳洲Deakin学位证,迪肯大学毕业证书1:1制作
澳洲Deakin学位证,迪肯大学毕业证书1:1制作
 
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作
美国IUB学位证,印第安纳大学伯明顿分校毕业证书1:1制作
 
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjekAIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
AIMA_ch3_L2-complement.ppt kjekfkjekjfkjefkjefkjek
 
Dubai Call Girls O525547819 Spring Break Fast Call Girls Dubai
Dubai Call Girls O525547819 Spring Break Fast Call Girls DubaiDubai Call Girls O525547819 Spring Break Fast Call Girls Dubai
Dubai Call Girls O525547819 Spring Break Fast Call Girls Dubai
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uk England Northern ...
 

Fpga 13-task-and-functions

  • 1. ENGR. RASHID FARID CHISHTI LECTURER, DEE, FET, IIUI CHISHTI@IIU.EDU.PK WEEK 13 TASK AND FUNCTIONS FPGA Based System Design Sunday, May 17, 2015 1 www.iiu.edu.pk
  • 2.  In verilog task can be used to code functionality that is repeated multiple times in a module.  A task has input, output and inout and can have its local variables.  All the variables defined in the module are also accessible in the task.  The task must be defined in the same module using task and endtask keywords.  To use a task in other modules, the task should be written in a separate file and the file then should be included using an `include directive in these modules.  The tasks are called from initial or always blocks or from other tasks in a module.  The task can contain any behavioral statements including timing control statements. Like module instantiation, the order of input, output and inout declarations in a task determines the order in which they must be mentioned for calling.  As tasks are called in a procedural block, the output must be of type reg , whereas the inputs may be of type reg or wire.  Verilog 2001 adds a keyword automatic to the task to define a reentrant task. www.iiu.edu.pk Sunday, May 17, 2015 Task 2
  • 3. // The following example designs a task FA and calls it in a loop four times to // generate a 4 bit ripple carry adder: module RCA( input [3:0] a, b, input c_in, output reg c_out, output reg [3:0] sum); reg carry[4:0]; integer i; task FA( input in1, in2, carry_in, output reg out, carry_out); assign {carry_out, out} = in1 + in2 + carry_in; endtask always@* begin carry[0] = c_in; for( i=0; i<4 ; i=i+1) begin FA(a[i], b[i], carry[i], sum[i], carry[i+1]); end c_out = carry[4]; end endmodule www.iiu.edu.pk Sunday, May 17, 2015 Task 3
  • 4.  Verilog function is in many respects like task as it also implements code that can be called several times inside a module.  A function is defined in the module using function and endfunction keywords.  The function can compute only one output. To compute this output, the function must have at least one input.  The output must be assigned to an implicit variable bearing the name and range of the function.  The range of the output is also specified with the function declaration.  A function in Verilog cannot use timing constructs like # or @ . A function can be called from a procedural block or continuous assignment statement.  It may also be called from other functions and tasks, whereas a function cannot call a task. A reentrant function can be designed by adding the automatic keyword.  A simple example here writes a function to implement a 2:1 multiplexer and then uses it three times to design a 4:1 multiplexer: www.iiu.edu.pk Sunday, May 17, 2015 Functions 4
  • 5. module MUX4to1( input [3:0] in, input [1:0] sel, output out); wire out1, out2; function MUX2to1; input in1, in2; input select; assign MUX2to1 select ? in2:in1; endfunction assign out1 = MUX2to1(in[0], in[1], sel[0]); assign out2 = MUX2to1(in[2], in[3], sel[0]); assign out = MUX2to1 (out1 ,out2, sel[1]); endmodule /* stimulus for testing the module MUX4to1 */ module testFunction; reg [3:0] IN; reg [1:0] SEL; wire OUT; MUX4to1 mux(IN, SEL, OUT); initial begin www.iiu.edu.pk Sunday, May 17, 2015 Functions 5
  • 6. IN = 1; SEL = 0; #5 IN = 7; SEL = 0; #5 IN = 2; SEL = 1; #5 IN = 4; SEL = 2; #5 IN = 8; SEL = 3; end initial $monitor ( $time, " %b %b %bn ", IN, SEL, OUT); endmodule www.iiu.edu.pk Sunday, May 17, 2015 Functions 6
  • 7. Task  A task can enable other tasks and functions.  Tasks may execute in non-zero simulation time.  Tasks may contain delay, event, or timing control statements.  Tasks may have zero or more arguments of type input, output, or inout.  Tasks do not return with a value, but can pass multiple values through output and inout arguments. Function  A function can enable another function but not another task.  Functions always execute in 0 simulation time.  Functions must not contain any delay, event, or timing control statements.  Functions must have at least one input argument. They can have more than one input.  Functions always return a single value. They cannot have output or inout arguments. www.iiu.edu.pk Sunday, May 17, 2015 Task and Function 7
  • 8. Task  Tasks are used for common Verilog code that contains delays, timing, event constructs, or multiple output arguments.  Tasks can have input, output, and inout arguments Function  Functions are used when common Verilog code is purely combinational, executes in zero simulation time, and provides exactly one output. Functions are typically used for conversions and commonly used calculations.  Functions can have input arguments. In addition, they can have local variables, registers, time variables, integers, real, or events. Task and Function Similarities  Both tasks and functions must be defined in a module and are local to the module.  Tasks or functions cannot have wires.  Tasks and functions contain behavioral statements only.  Tasks and functions do not contain always or initial statements but are called from always blocks, initial blocks, or other tasks and functions. www.iiu.edu.pk Sunday, May 17, 2015 Task and Function 8