SlideShare uma empresa 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

Mais conteĂșdo relacionado

Mais procurados

SDR channelizer by sooraj
SDR channelizer by soorajSDR channelizer by sooraj
SDR channelizer by sooraj
sooraj yadav
 
Design and implementation of low power
Design and implementation of low powerDesign and implementation of low power
Design and implementation of low power
Surendra Bommavarapu
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
TAlha MAlik
 

Mais procurados (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
 

Semelhante a Fpga 13-task-and-functions

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
ankit482504
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 

Semelhante 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
 
Functions part1
Functions part1Functions part1
Functions part1
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2
 
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
 

Mais 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-encoding
Malik Tauqir Hasan
 
Fpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machineFpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machine
Malik Tauqir Hasan
 
Fpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machineFpga 08-behavioral-modeling-mealy-machine
Fpga 08-behavioral-modeling-mealy-machine
Malik 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-adder
Malik 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-directives
Malik Tauqir Hasan
 
Fpga 05-verilog-programming
Fpga 05-verilog-programmingFpga 05-verilog-programming
Fpga 05-verilog-programming
Malik Tauqir Hasan
 
Fpga 04-verilog-programming
Fpga 04-verilog-programmingFpga 04-verilog-programming
Fpga 04-verilog-programming
Malik Tauqir Hasan
 
Fpga 02-memory-and-pl ds
Fpga 02-memory-and-pl dsFpga 02-memory-and-pl ds
Fpga 02-memory-and-pl ds
Malik Tauqir Hasan
 
Fpga 01-digital-logic-design
Fpga 01-digital-logic-designFpga 01-digital-logic-design
Fpga 01-digital-logic-design
Malik Tauqir Hasan
 

Mais 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

Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
drmarathore
 
âž„đŸ” 7737669865 đŸ”â–» kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...
âž„đŸ” 7737669865 đŸ”â–» kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...âž„đŸ” 7737669865 đŸ”â–» kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...
âž„đŸ” 7737669865 đŸ”â–» kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...
amitlee9823
 
CHEAP Call Girls in Mayapuri (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Mayapuri  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Mayapuri  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Mayapuri (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
amitlee9823
 
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Naicy mandal
 
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
amitlee9823
 
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
amitlee9823
 
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in DammamAbortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
ahmedjiabur940
 
CHEAP Call Girls in Ashok Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Ashok Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Ashok Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Ashok Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
motiram463
 
âž„đŸ” 7737669865 đŸ”â–» Deoghar Call-girls in Women Seeking Men 🔝Deoghar🔝 Escorts...
âž„đŸ” 7737669865 đŸ”â–» Deoghar Call-girls in Women Seeking Men  🔝Deoghar🔝   Escorts...âž„đŸ” 7737669865 đŸ”â–» Deoghar Call-girls in Women Seeking Men  🔝Deoghar🔝   Escorts...
âž„đŸ” 7737669865 đŸ”â–» Deoghar Call-girls in Women Seeking Men 🔝Deoghar🔝 Escorts...
amitlee9823
 
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
amitlee9823
 

Último (20)

Shikrapur Call Girls Most Awaited Fun 6297143586 High Profiles young Beautie...
Shikrapur Call Girls Most Awaited Fun  6297143586 High Profiles young Beautie...Shikrapur Call Girls Most Awaited Fun  6297143586 High Profiles young Beautie...
Shikrapur Call Girls Most Awaited Fun 6297143586 High Profiles young Beautie...
 
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
 
âž„đŸ” 7737669865 đŸ”â–» kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...
âž„đŸ” 7737669865 đŸ”â–» kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...âž„đŸ” 7737669865 đŸ”â–» kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...
âž„đŸ” 7737669865 đŸ”â–» kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...
 
Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006
 
CHEAP Call Girls in Mayapuri (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Mayapuri  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Mayapuri  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Mayapuri (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
 
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
 
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
 
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
 
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
SM-N975F esquematico completo - reparaciĂłn.pdf
SM-N975F esquematico completo - reparaciĂłn.pdfSM-N975F esquematico completo - reparaciĂłn.pdf
SM-N975F esquematico completo - reparaciĂłn.pdf
 
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in DammamAbortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
 
CHEAP Call Girls in Ashok Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Ashok Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Ashok Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Ashok Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
 
âž„đŸ” 7737669865 đŸ”â–» Deoghar Call-girls in Women Seeking Men 🔝Deoghar🔝 Escorts...
âž„đŸ” 7737669865 đŸ”â–» Deoghar Call-girls in Women Seeking Men  🔝Deoghar🔝   Escorts...âž„đŸ” 7737669865 đŸ”â–» Deoghar Call-girls in Women Seeking Men  🔝Deoghar🔝   Escorts...
âž„đŸ” 7737669865 đŸ”â–» Deoghar Call-girls in Women Seeking Men 🔝Deoghar🔝 Escorts...
 
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
 
(INDIRA) Call Girl Napur Call Now 8617697112 Napur Escorts 24x7
(INDIRA) Call Girl Napur Call Now 8617697112 Napur Escorts 24x7(INDIRA) Call Girl Napur Call Now 8617697112 Napur Escorts 24x7
(INDIRA) Call Girl Napur Call Now 8617697112 Napur Escorts 24x7
 

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