SlideShare ist ein Scribd-Unternehmen logo
1 von 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 !!

Weitere ähnliche Inhalte

Was ist angesagt?

Design of Elevator Controller using Verilog HDL
Design of Elevator Controller using Verilog HDLDesign of Elevator Controller using Verilog HDL
Design of Elevator Controller using Verilog HDL
Vishesh Thakur
 

Was ist angesagt? (20)

System verilog important
System verilog importantSystem verilog important
System verilog important
 
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 operators.pptx
Verilog  operators.pptxVerilog  operators.pptx
Verilog operators.pptx
 
Advance Peripheral Bus
Advance Peripheral Bus Advance Peripheral Bus
Advance Peripheral Bus
 
Verilog Test Bench
Verilog Test BenchVerilog Test Bench
Verilog Test Bench
 
Verilog
VerilogVerilog
Verilog
 
Ral by pushpa
Ral by pushpa Ral by pushpa
Ral by pushpa
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
System verilog coverage
System verilog coverageSystem verilog coverage
System verilog coverage
 
8 Bit ALU
8 Bit ALU8 Bit ALU
8 Bit ALU
 
Design of Elevator Controller using Verilog HDL
Design of Elevator Controller using Verilog HDLDesign of Elevator Controller using Verilog HDL
Design of Elevator Controller using Verilog HDL
 
SPI Bus Protocol
SPI Bus ProtocolSPI Bus Protocol
SPI Bus Protocol
 
Tutorial getting started with RISC-V verification
Tutorial getting started with RISC-V verificationTutorial getting started with RISC-V verification
Tutorial getting started with RISC-V verification
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 
Vhdl 1 ppg
Vhdl 1 ppgVhdl 1 ppg
Vhdl 1 ppg
 
Data types in verilog
Data types in verilogData types in verilog
Data types in verilog
 
verilog code for logic gates
verilog code for logic gatesverilog code for logic gates
verilog code for logic gates
 
Verilog full adder in dataflow & gate level modelling style.
Verilog full adder in dataflow  & gate level modelling style.Verilog full adder in dataflow  & gate level modelling style.
Verilog full adder in dataflow & gate level modelling style.
 
Booth Multiplier
Booth MultiplierBooth Multiplier
Booth Multiplier
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Dr.YNM

Mehr von 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
 

Kürzlich hochgeladen

Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Kürzlich hochgeladen (20)

Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
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
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 

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 !!

Hinweis der Redaktion

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