SlideShare una empresa de Scribd logo
1 de 25
VERILOG TASKS & FUNCTIONS
INTRODUCTION
• The Tasks & Functions in Verilog help to reduce
the complexity by breaking up the large
behavioural designs into smaller pieces and make
the overall code simple and clean.
• Tasks and functions allow the designer to abstract
Verilog code that is used at many places in the
design.
• Tasks have input, output, & inout arguments where
as Functions have input arguments. So, values can
be passed into and out from tasks and functions.
contd
• A task is similar to a function, but unlike a
function it has both input and output ports.
• Therefore tasks do not return values. Tasks are
similar to procedures in most programming
languages.
• The purpose of a function is to respond to an input
value by returning a single value.
• A task can support multiple goals and can
calculate multiple result values.
• It cannot be used in an expression. Parameters may
be passed to it and results are returned.
• A Verilog task is similar to a software procedure. It
is called from a calling statement and after
execution, returns to the next statement.
• A task is defined within a module using the
keywords task and endtask and it is called from
within the always statement.
• Local variables may be declared within it and their
scope will be the task.
• The order of task parameters at the calling site must
correspond to the order of definitions within the
task
TASK
contd
• A task may call itself, or be called from tasks that it
has called.
• However, as in a hardware implementation, there is
only one set of registers to hold the task variables.
• Thus, the registers used after the second call to the task are
the same physical entities as those in the previous call(s).
• The simulator maintains the thread of control so that the
returns from a task called multiple times are handled
correctly.
23 June 2020 yayavaram@yahoo.com 5
Basic structure of a task
• module this_task;
task my_task;
input a, b;
inout c;
output d, e;
reg foo1, foo2, foo3;
begin
<statements> // the set of statements that
performs the work of the task
23 June 2020 yayavaram@yahoo.com 6
contd
c = foo1; // the assignments that initialize
d = foo2; // the results variables
e = foo3;
end
endtask
endmodule
23 June 2020 yayavaram@yahoo.com 7
Ex:Task (Procedure)
task average; // task declaration
input a; // declaration of ports
input b; //
output Av ;
wire s ;
reg Av;
assign s = (a+b+c);
assign Av= s / 3;
endtask
23 June 2020 yayavaram@yahoo.com 8
System Tasks
• Verilog provides standard system tasks for certain
routine operations.
• All system tasks appear in the form $<keyword>.
• Operations such as displaying on the screen,
monitoring values of nets, stopping, and finishing
are done by system tasks.
• For ex: $display ; $stop; $finish ; $ monitor etc.
23 June 2020 yayavaram@yahoo.com 9
$display
• $display is the main system task for displaying
values of variables or strings or expressions.
• Usage: $display(s1, s2, s3,.....,sn); s1, s2, s3,..., sn
can be quoted strings or variables or expressions.
• Note: The format of $display is very similar to printf
in C.
• A $display inserts a newline at the end of the string
by default.
• A $display without any arguments produces a
newline.
23 June 2020 yayavaram@yahoo.com 10
Examples
• $display("Hello Verilog World");
-- Hello Verilog World
//To display value of current simulation time 230
• $display($time);
-- 230
//Display the value of port_id 5 in binary
• reg [4:0] port_id;
• $display("ID of the port is %b", port_id);
-- ID of the port is 00101
23 June 2020 yayavaram@yahoo.com 11
contd
• //Display x characters //Display value of 4-bit bus
10xx (signal contention) in binary
• reg [3:0] bus;
• $display("Bus value is %b", bus);
-- Bus value is 10xx.
23 June 2020 yayavaram@yahoo.com 12
Monitor
• Verilog provides a mechanism to monitor a signal
when its value changes and this is provided by the
task $monitor.
• Usage: $monitor(p1,p2,p3,....,pn);The parameters
p1, p2, ... , pn can be variables, signal names, or
quoted strings.
• Only one monitoring list is active at a time. If there
is more than one $monitor statement in the
simulation, the last $monitor will only be active.
• The earlier $monitor statements will be ignored.
23 June 2020 yayavaram@yahoo.com 13
contd
• Two tasks are used to switch the monitoring on and
off.
For ex: $monitoron ; $monitoroff ;
• The task $monitoron enables monitoring, and the
$monitoroff task disables monitoring during a
simulation.
• Monitoring is turned on by default at the beginning
of the simulation and can be controlled during the
simulation with the $monitoron and $monitoroff
tasks.
23 June 2020 yayavaram@yahoo.com 14
$stop
• The task , $stop is used to stop the simulation.
Usage: $stop ;
• The $stop task puts the simulation in an interactive
mode.
• The $stop task is used whenever the designer wish
to suspend the simulation and examine the values of
signals in the design.
• The $finish task terminates or finishes the
simulation.
Usage: $finish;
23 June 2020 yayavaram@yahoo.com 15
Ex: Stop &Finish
// Stop at time 100 in the simulation and examine the
results.// Finish the simulation at time 1000.
initial begin
clock = 0;
reset = 1;
#100 $stop; // suspend the simulation at time = 100
#900 $finish; // terminate the simulation at time = 1000
end
23 June 2020 yayavaram@yahoo.com 16
FUNCTIONS
• Functions are similar to tasks, except that functions
return only a single value to the expression from
which they are called.
• Like tasks, functions provide the ability to execute
common procedures from within a module.
• A function can be invoked from a continuous
assignment statement or from within a procedural
statement and is represented by an operand in an
expression.
23 June 2020 yayavaram@yahoo.com 17
contd
• Functions cannot contain delays, timing, or event
control statements and execute in zero simulation time.
• Although functions can invoke other functions, they are
not recursive.
• Functions cannot invoke a task.
• Functions must have at least one input argument, but
cannot have output or inout arguments.
• A function is invoked from an expression. The function
is invoked by specifying the function name together
with the input parameters. The syntax is as below.
function name (expr1, expr2, . . . , exprN);
23 June 2020 yayavaram@yahoo.com 18
Function Syntax
function [range or type] function name
input declaration
other declarations
begin
statements
end
endfunction
23 June 2020 yayavaram@yahoo.com 19
Function-Example
function mux;
input a, b, c, d;
input [1:0] select;
case (select)
2'b00: mux = a;
2'b01: mux = b;
2'b10: mux = c;
2'b11: mux = d;
default: mux = 'bx;
endcase
endfunction23 June 2020 yayavaram@yahoo.com 20
Function for a half adder
• //module for a half adder using a function
module funct_half_add;
reg a, b;
reg [1:0] sum;
initial
begin
sum = half_add (1'b0, 1'b0);
$display ("a=0, b=0, cout, sum = %b", sum);
sum = half_add (1'b0, 1'b1);
23 June 2020 yayavaram@yahoo.com 21
contd
$display ("a=0, b=1, cout, sum = %b", sum);
sum = half_add (1'b1, 1'b0);
$display ("a=1, b=0, cout, sum = %b", sum);
sum = half_add (1'b1, 1'b1);
$display ("a=1, b=1, cout, sum = %b", sum);
end
function [1:0] half_add;
input a, b;
reg [1:0] sum;
begin23 June 2020 yayavaram@yahoo.com 22
contd
case ({a,b})
2'b00: sum = 2'b00;
2'b01: sum = 2'b01;
2'b10: sum = 2'b01;
2'b11: sum = 2'b10;
default:sum = 2'bxx;
endcase
half_add = sum;
end
endfunction
endmodule
23 June 2020 yayavaram@yahoo.com 23
Differences
23 June 2020 25yayavaram@yahoo.com
THANQ FOR WATCHINIG
GOOD LUCK !!

Más contenido relacionado

La actualidad más candente

Session 7 code_functional_coverage
Session 7 code_functional_coverageSession 7 code_functional_coverage
Session 7 code_functional_coverage
Nirav Desai
 
Session 6 sv_randomization
Session 6 sv_randomizationSession 6 sv_randomization
Session 6 sv_randomization
Nirav Desai
 
Day2 Verilog HDL Basic
Day2 Verilog HDL BasicDay2 Verilog HDL Basic
Day2 Verilog HDL Basic
Ron Liu
 

La actualidad más candente (20)

How to create SystemVerilog verification environment?
How to create SystemVerilog verification environment?How to create SystemVerilog verification environment?
How to create SystemVerilog verification environment?
 
VERILOG CODE FOR Adder
VERILOG CODE FOR AdderVERILOG CODE FOR Adder
VERILOG CODE FOR Adder
 
Vhdl programming
Vhdl programmingVhdl programming
Vhdl programming
 
System verilog assertions
System verilog assertionsSystem verilog assertions
System verilog assertions
 
Verilog Test Bench
Verilog Test BenchVerilog Test Bench
Verilog Test Bench
 
Session 7 code_functional_coverage
Session 7 code_functional_coverageSession 7 code_functional_coverage
Session 7 code_functional_coverage
 
System verilog important
System verilog importantSystem verilog important
System verilog important
 
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)
 
Session 6 sv_randomization
Session 6 sv_randomizationSession 6 sv_randomization
Session 6 sv_randomization
 
Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
 
Verilog presentation final
Verilog presentation finalVerilog presentation final
Verilog presentation final
 
UVM TUTORIAL;
UVM TUTORIAL;UVM TUTORIAL;
UVM TUTORIAL;
 
axi protocol
axi protocolaxi protocol
axi protocol
 
Day2 Verilog HDL Basic
Day2 Verilog HDL BasicDay2 Verilog HDL Basic
Day2 Verilog HDL Basic
 
Concepts of Behavioral modelling in Verilog HDL
Concepts of Behavioral modelling in Verilog HDLConcepts of Behavioral modelling in Verilog HDL
Concepts of Behavioral modelling in Verilog HDL
 
Synchronous and asynchronous clock
Synchronous and asynchronous clockSynchronous and asynchronous clock
Synchronous and asynchronous clock
 
Verilog operators.pptx
Verilog  operators.pptxVerilog  operators.pptx
Verilog operators.pptx
 
Ral by pushpa
Ral by pushpa Ral by pushpa
Ral by pushpa
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
system verilog
system verilogsystem verilog
system verilog
 

Similar a Verilog TASKS & FUNCTIONS

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
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 

Similar a Verilog TASKS & FUNCTIONS (20)

Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
 
Plsql
PlsqlPlsql
Plsql
 
Fpga 13-task-and-functions
Fpga 13-task-and-functionsFpga 13-task-and-functions
Fpga 13-task-and-functions
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11
 
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
 
Function
FunctionFunction
Function
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
 
Functions in C.pptx
Functions in C.pptxFunctions in C.pptx
Functions in C.pptx
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
Functions
FunctionsFunctions
Functions
 
Function
Function Function
Function
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Lec16-CS110 Computational Engineering
Lec16-CS110 Computational EngineeringLec16-CS110 Computational Engineering
Lec16-CS110 Computational Engineering
 
Modular programming
Modular programmingModular programming
Modular programming
 
Inline function
Inline functionInline function
Inline function
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: Serversideness
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdf
 

Más de Dr.YNM

Más de Dr.YNM (20)

Introduction to DSP.ppt
Introduction to DSP.pptIntroduction to DSP.ppt
Introduction to DSP.ppt
 
Atmel.ppt
Atmel.pptAtmel.ppt
Atmel.ppt
 
PIC Microcontrollers.ppt
PIC Microcontrollers.pptPIC Microcontrollers.ppt
PIC Microcontrollers.ppt
 
Crystalstructure-.ppt
Crystalstructure-.pptCrystalstructure-.ppt
Crystalstructure-.ppt
 
Basics of OS & RTOS.ppt
Basics of OS & RTOS.pptBasics of OS & RTOS.ppt
Basics of OS & RTOS.ppt
 
Introducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxIntroducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptx
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.ppt
 
Introduction to ASICs.pptx
Introduction to ASICs.pptxIntroduction to ASICs.pptx
Introduction to ASICs.pptx
 
VHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptVHDL-PRESENTATION.ppt
VHDL-PRESENTATION.ppt
 
Basics of data communications.pptx
Basics of data communications.pptxBasics of data communications.pptx
Basics of data communications.pptx
 
CPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptxCPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptx
 
Transient response of RC , RL circuits with step input
Transient response of RC , RL circuits  with step inputTransient response of RC , RL circuits  with step input
Transient response of RC , RL circuits with step input
 
CISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURESCISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURES
 
Lect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTURELect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTURE
 
Lect 3 ARM PROCESSOR ARCHITECTURE
Lect 3  ARM PROCESSOR ARCHITECTURE Lect 3  ARM PROCESSOR ARCHITECTURE
Lect 3 ARM PROCESSOR ARCHITECTURE
 
Microprocessor Architecture 4
Microprocessor Architecture  4Microprocessor Architecture  4
Microprocessor Architecture 4
 
Lect 2 ARM processor architecture
Lect 2 ARM processor architectureLect 2 ARM processor architecture
Lect 2 ARM processor architecture
 
Microprocessor Architecture-III
Microprocessor Architecture-IIIMicroprocessor Architecture-III
Microprocessor Architecture-III
 
LECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSLECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORS
 
Microprocessor architecture II
Microprocessor architecture   IIMicroprocessor architecture   II
Microprocessor architecture II
 

Último

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Último (20)

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 

Verilog TASKS & FUNCTIONS

  • 1. VERILOG TASKS & FUNCTIONS
  • 2. INTRODUCTION • The Tasks & Functions in Verilog help to reduce the complexity by breaking up the large behavioural designs into smaller pieces and make the overall code simple and clean. • Tasks and functions allow the designer to abstract Verilog code that is used at many places in the design. • Tasks have input, output, & inout arguments where as Functions have input arguments. So, values can be passed into and out from tasks and functions.
  • 3. contd • A task is similar to a function, but unlike a function it has both input and output ports. • Therefore tasks do not return values. Tasks are similar to procedures in most programming languages. • The purpose of a function is to respond to an input value by returning a single value. • A task can support multiple goals and can calculate multiple result values. • It cannot be used in an expression. Parameters may be passed to it and results are returned.
  • 4. • A Verilog task is similar to a software procedure. It is called from a calling statement and after execution, returns to the next statement. • A task is defined within a module using the keywords task and endtask and it is called from within the always statement. • Local variables may be declared within it and their scope will be the task. • The order of task parameters at the calling site must correspond to the order of definitions within the task TASK
  • 5. contd • A task may call itself, or be called from tasks that it has called. • However, as in a hardware implementation, there is only one set of registers to hold the task variables. • Thus, the registers used after the second call to the task are the same physical entities as those in the previous call(s). • The simulator maintains the thread of control so that the returns from a task called multiple times are handled correctly. 23 June 2020 yayavaram@yahoo.com 5
  • 6. Basic structure of a task • module this_task; task my_task; input a, b; inout c; output d, e; reg foo1, foo2, foo3; begin <statements> // the set of statements that performs the work of the task 23 June 2020 yayavaram@yahoo.com 6
  • 7. contd c = foo1; // the assignments that initialize d = foo2; // the results variables e = foo3; end endtask endmodule 23 June 2020 yayavaram@yahoo.com 7
  • 8. Ex:Task (Procedure) task average; // task declaration input a; // declaration of ports input b; // output Av ; wire s ; reg Av; assign s = (a+b+c); assign Av= s / 3; endtask 23 June 2020 yayavaram@yahoo.com 8
  • 9. System Tasks • Verilog provides standard system tasks for certain routine operations. • All system tasks appear in the form $<keyword>. • Operations such as displaying on the screen, monitoring values of nets, stopping, and finishing are done by system tasks. • For ex: $display ; $stop; $finish ; $ monitor etc. 23 June 2020 yayavaram@yahoo.com 9
  • 10. $display • $display is the main system task for displaying values of variables or strings or expressions. • Usage: $display(s1, s2, s3,.....,sn); s1, s2, s3,..., sn can be quoted strings or variables or expressions. • Note: The format of $display is very similar to printf in C. • A $display inserts a newline at the end of the string by default. • A $display without any arguments produces a newline. 23 June 2020 yayavaram@yahoo.com 10
  • 11. Examples • $display("Hello Verilog World"); -- Hello Verilog World //To display value of current simulation time 230 • $display($time); -- 230 //Display the value of port_id 5 in binary • reg [4:0] port_id; • $display("ID of the port is %b", port_id); -- ID of the port is 00101 23 June 2020 yayavaram@yahoo.com 11
  • 12. contd • //Display x characters //Display value of 4-bit bus 10xx (signal contention) in binary • reg [3:0] bus; • $display("Bus value is %b", bus); -- Bus value is 10xx. 23 June 2020 yayavaram@yahoo.com 12
  • 13. Monitor • Verilog provides a mechanism to monitor a signal when its value changes and this is provided by the task $monitor. • Usage: $monitor(p1,p2,p3,....,pn);The parameters p1, p2, ... , pn can be variables, signal names, or quoted strings. • Only one monitoring list is active at a time. If there is more than one $monitor statement in the simulation, the last $monitor will only be active. • The earlier $monitor statements will be ignored. 23 June 2020 yayavaram@yahoo.com 13
  • 14. contd • Two tasks are used to switch the monitoring on and off. For ex: $monitoron ; $monitoroff ; • The task $monitoron enables monitoring, and the $monitoroff task disables monitoring during a simulation. • Monitoring is turned on by default at the beginning of the simulation and can be controlled during the simulation with the $monitoron and $monitoroff tasks. 23 June 2020 yayavaram@yahoo.com 14
  • 15. $stop • The task , $stop is used to stop the simulation. Usage: $stop ; • The $stop task puts the simulation in an interactive mode. • The $stop task is used whenever the designer wish to suspend the simulation and examine the values of signals in the design. • The $finish task terminates or finishes the simulation. Usage: $finish; 23 June 2020 yayavaram@yahoo.com 15
  • 16. Ex: Stop &Finish // Stop at time 100 in the simulation and examine the results.// Finish the simulation at time 1000. initial begin clock = 0; reset = 1; #100 $stop; // suspend the simulation at time = 100 #900 $finish; // terminate the simulation at time = 1000 end 23 June 2020 yayavaram@yahoo.com 16
  • 17. FUNCTIONS • Functions are similar to tasks, except that functions return only a single value to the expression from which they are called. • Like tasks, functions provide the ability to execute common procedures from within a module. • A function can be invoked from a continuous assignment statement or from within a procedural statement and is represented by an operand in an expression. 23 June 2020 yayavaram@yahoo.com 17
  • 18. contd • Functions cannot contain delays, timing, or event control statements and execute in zero simulation time. • Although functions can invoke other functions, they are not recursive. • Functions cannot invoke a task. • Functions must have at least one input argument, but cannot have output or inout arguments. • A function is invoked from an expression. The function is invoked by specifying the function name together with the input parameters. The syntax is as below. function name (expr1, expr2, . . . , exprN); 23 June 2020 yayavaram@yahoo.com 18
  • 19. Function Syntax function [range or type] function name input declaration other declarations begin statements end endfunction 23 June 2020 yayavaram@yahoo.com 19
  • 20. Function-Example function mux; input a, b, c, d; input [1:0] select; case (select) 2'b00: mux = a; 2'b01: mux = b; 2'b10: mux = c; 2'b11: mux = d; default: mux = 'bx; endcase endfunction23 June 2020 yayavaram@yahoo.com 20
  • 21. Function for a half adder • //module for a half adder using a function module funct_half_add; reg a, b; reg [1:0] sum; initial begin sum = half_add (1'b0, 1'b0); $display ("a=0, b=0, cout, sum = %b", sum); sum = half_add (1'b0, 1'b1); 23 June 2020 yayavaram@yahoo.com 21
  • 22. contd $display ("a=0, b=1, cout, sum = %b", sum); sum = half_add (1'b1, 1'b0); $display ("a=1, b=0, cout, sum = %b", sum); sum = half_add (1'b1, 1'b1); $display ("a=1, b=1, cout, sum = %b", sum); end function [1:0] half_add; input a, b; reg [1:0] sum; begin23 June 2020 yayavaram@yahoo.com 22
  • 23. contd case ({a,b}) 2'b00: sum = 2'b00; 2'b01: sum = 2'b01; 2'b10: sum = 2'b01; 2'b11: sum = 2'b10; default:sum = 2'bxx; endcase half_add = sum; end endfunction endmodule 23 June 2020 yayavaram@yahoo.com 23
  • 25. 23 June 2020 25yayavaram@yahoo.com THANQ FOR WATCHINIG GOOD LUCK !!

Notas del editor

  1. If the value of S is 1 ,then Y= B other wise Y= A