SlideShare a Scribd company logo
Chapter 8
Counters & Time Delays
Counters & Time Delays
• Counters are used for keep track of events like in
For loop
• Delays are used in setting up reasonably accurate
timing between two events
• Counters and time delays can be implemented
either on
– Software
– Hardware
• Both are implemented with Loop construct
• What is appropriate for counter and Time Delay
– Counts Time duration
– Counts Number of iteration
Counters
• A loop counter is set up by loading a register with
a certain value
• Then using the DCR (to decrement) and INR (to
increment) the contents of the register are
updated.
• A loop is set up with a conditional jump
instruction that loops back or not depending on
whether the count has reached the termination
count.
Counters
• The operation of a loop counter can be described
using the following flowchart.
Initialize
Update the count
Is this
Final
Count?
Body of loop
No
Yes
Delays
• It was shown in Chapter 2 that each instruction
passes through different combinations of Fetch,
Memory Read, and Memory Write cycles.
• Knowing the combinations of cycles, one can
calculate how long such an instruction would
require to complete.
• The table in Appendix F of the book contains a
column with the title B/M/T.
– B for Number of Bytes
– M for Number of Machine Cycles
– T for Number of T-State.
Delays
• Knowing how many T-States an instruction
requires, and keeping in mind that a T-State is
one clock cycle long, we can calculate the time
using the following formula:
Delay = No. of T-States / Frequency
• For example a “MVI” instruction uses 7 T-States.
Therefore, if the Microprocessor is running at 2
MHz, the instruction would require 3.5 µSeconds
to complete.
Delay loops
• We can use a loop to produce a certain amount
of time delay in a program.
• The following is an example of a delay loop:
MVI C, FFH 7 T-States
LOOP DCR C 4 T-States
JNZ LOOP 10 T-States
• The first instruction initializes the loop counter and is executed
only once requiring only 7 T-States.
• The following two instructions form a loop that requires 14 T-
States to execute and is repeated 255 times until C becomes 0.
Delay Loops (Contd.)
• We need to keep in mind though that in the last iteration of the
loop, the JNZ instruction will fail and require only 7 T-States
rather than the 10.
• Therefore, we must deduct 3 T-States from the total delay to get
an accurate delay calculation.
• To calculate the delay, we use the following formula:
Tdelay = TO + TL
– Tdelay = total delay
– TO = delay outside the loop
– TL = delay of the loop
• TO is the sum of all delays outside the loop.
• TL is calculated using the formula
TL = T X Loop T-States X N10
Delay Loops (Contd.)
• Using these formulas, we can calculate the time
delay for the previous example:
• TO = 7 T-States
– Delay of the MVI instruction
• TL = (14 X 255) - 3 = 3567 T-States
– 14 T-States for the 2 instructions repeated 255 times
(FF16 = 25510) reduced by the 3 T-States for the final JNZ.
• TDelay = (7 + 3567) X 0.5 µSec = 1.787 mSec
– Assuming f = 2 MHz
Using a Register Pair as a Loop Counter
• Using a single register, one can repeat a loop for
a maximum count of 255 times.
• It is possible to increase this count by using a
register pair for the loop counter instead of the
single register.
– A minor problem arises in how to test for the final
count since DCX and INX do not modify the flags.
– However, if the loop is looking for when the count
becomes zero, we can use a small trick by ORing
the two registers in the pair and then checking the
zero flag.
Using a Register Pair as a Loop Counter
• The following is an example of a delay loop set
up with a register pair as the loop counter.
LXI B, 1000H 10 T-States
LOOP DCX B 6 T-States
MOV A, C 4 T-States
ORA B 4 T-States
JNZ LOOP 10 T-States
Using a Register Pair as a Loop Counter
• Using the same formula from before, we can
calculate:
• TO = 10 T-States
– The delay for the LXI instruction
• TL = (24 X 4096) - 3 = 98301 T- States
– 24 T-States for the 4 instructions in the loop repeated
4096 times (100016 = 409610) reduced by the 3 T-States for
the JNZ in the last iteration.
• TDelay = (10 + 98301) X 0.5 mSec = 49.155 mSec
Nested Loops
• Nested loops can be
easily setup in
Assembly language by
using two registers for
the two loop counters
and updating the right
register in the right
loop.
– In the figure, the body
of loop2 can be before
or after loop1.
Initialize loop 1
Update the count1
Is this
Final
Count?
Body of loop 1
No
Yes
Initialize loop 2
Body of loop 2
Update the count 2
Is this
Final
Count?
No
Yes
Nested Loops for Delay
• Instead (or in conjunction with) Register Pairs, a
nested loop structure can be used to increase
the total delay produced.
MVI B, 10H 7 T-States
LOOP2 MVI C, FFH 7 T-States
LOOP1 DCR C 4 T-States
JNZ LOOP1 10 T-States
DCR B 4 T-States
JNZ LOOP2 10 T-States
Delay Calculation of Nested Loops
• The calculation remains the same except that it
the formula must be applied recursively to each
loop.
– Start with the inner loop, then plug that delay in
the calculation of the outer loop.
• Delay of inner loop
– TO1 = 7 T-States
• MVI C, FFH instruction
– TL1 = (255 X 14) - 3 = 3567 T-States
• 14 T-States for the DCR C and JNZ instructions repeated 255
times (FF16 = 25510) minus 3 for the final JNZ.
– TLOOP1 = 7 + 3567 = 3574 T-States
Delay Calculation of Nested Loops
• Delay of outer loop
– TO2 = 7 T-States
• MVI B, 10H instruction
– TL1 = (16 X (14 + 3574)) - 3 = 57405 T-States
• 14 T-States for the DCR B and JNZ instructions and 3574
T-States for loop1 repeated 16 times (1016 = 1610) minus 3 for the
final JNZ.
– TDelay = 7 + 57405 = 57412 T-States
• Total Delay
– TDelay = 57412 X 0.5 µSec = 28.706 mSec
Increasing the delay
• The delay can be further increased by using
register pairs for each of the loop counters in the
nested loops setup.
• It can also be increased by adding dummy
instructions (like NOP) in the body of the loop.

More Related Content

What's hot

Microprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 FeaturesMicroprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 Features
Srikrishna Thota
 
8051 Addressing Modes
8051 Addressing Modes8051 Addressing Modes
8051 Addressing Modes
Senthil Kumar
 
Memory Segmentation of 8086
Memory Segmentation of 8086Memory Segmentation of 8086
Memory Segmentation of 8086
Nikhil Kumar
 
8051 microcontroller and it’s interface
8051 microcontroller and it’s interface8051 microcontroller and it’s interface
8051 microcontroller and it’s interface
Abhishek Choksi
 
8086 microprocessor
8086 microprocessor8086 microprocessor
8086 microprocessor
VEERA BOOPATHY E
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086
saurav kumar
 
Stack in 8085 microprocessor
Stack in 8085 microprocessorStack in 8085 microprocessor
Stack in 8085 microprocessor
hepzijustin
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
Shivashankar Sawalgi
 
8155 PPI
8155 PPI8155 PPI
8155 PPI
ShivamSood22
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
Sudhanshu Janwadkar
 
Time delays & counter.ppt
Time delays & counter.pptTime delays & counter.ppt
Time delays & counter.ppt
ISMT College
 
8051,chapter1,architecture and peripherals
8051,chapter1,architecture and peripherals8051,chapter1,architecture and peripherals
8051,chapter1,architecture and peripherals
amrutachintawar239
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
prasadpawaskar
 
8051 Presentation
8051 Presentation8051 Presentation
8051 Presentation
Sayan Chakraborty
 
8086
80868086
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051
ssuser3a47cb
 
8085 Architecture & Memory Interfacing1
8085 Architecture & Memory Interfacing18085 Architecture & Memory Interfacing1
8085 Architecture & Memory Interfacing1
techbed
 
Memory interfacing of microprocessor 8085
Memory interfacing of microprocessor 8085Memory interfacing of microprocessor 8085
Memory interfacing of microprocessor 8085
Nilesh Bhaskarrao Bahadure
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
MemonaMemon1
 
8085 microproceesor ppt
8085 microproceesor ppt8085 microproceesor ppt
8085 microproceesor ppt
RJ Aniket
 

What's hot (20)

Microprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 FeaturesMicroprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 Features
 
8051 Addressing Modes
8051 Addressing Modes8051 Addressing Modes
8051 Addressing Modes
 
Memory Segmentation of 8086
Memory Segmentation of 8086Memory Segmentation of 8086
Memory Segmentation of 8086
 
8051 microcontroller and it’s interface
8051 microcontroller and it’s interface8051 microcontroller and it’s interface
8051 microcontroller and it’s interface
 
8086 microprocessor
8086 microprocessor8086 microprocessor
8086 microprocessor
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086
 
Stack in 8085 microprocessor
Stack in 8085 microprocessorStack in 8085 microprocessor
Stack in 8085 microprocessor
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
8155 PPI
8155 PPI8155 PPI
8155 PPI
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
Time delays & counter.ppt
Time delays & counter.pptTime delays & counter.ppt
Time delays & counter.ppt
 
8051,chapter1,architecture and peripherals
8051,chapter1,architecture and peripherals8051,chapter1,architecture and peripherals
8051,chapter1,architecture and peripherals
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
 
8051 Presentation
8051 Presentation8051 Presentation
8051 Presentation
 
8086
80868086
8086
 
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051
 
8085 Architecture & Memory Interfacing1
8085 Architecture & Memory Interfacing18085 Architecture & Memory Interfacing1
8085 Architecture & Memory Interfacing1
 
Memory interfacing of microprocessor 8085
Memory interfacing of microprocessor 8085Memory interfacing of microprocessor 8085
Memory interfacing of microprocessor 8085
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
 
8085 microproceesor ppt
8085 microproceesor ppt8085 microproceesor ppt
8085 microproceesor ppt
 

Similar to Chapter 8

8.1 Counters & Time Delays.pptx
8.1 Counters & Time Delays.pptx8.1 Counters & Time Delays.pptx
8.1 Counters & Time Delays.pptx
Devashish397099
 
8085-Programming-II-mod-1.pptx
8085-Programming-II-mod-1.pptx8085-Programming-II-mod-1.pptx
8085-Programming-II-mod-1.pptx
Asmita Bhagdikar
 
Delay routine
Delay routineDelay routine
Delay routine
Yash Gandhi
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
Khalid Hasan
 
computer architecture 4
computer architecture 4 computer architecture 4
computer architecture 4
Dr.Umadevi V
 
Timing & Control.pptx
Timing & Control.pptxTiming & Control.pptx
Rtl design optimizations and tradeoffs
Rtl design optimizations and tradeoffsRtl design optimizations and tradeoffs
Rtl design optimizations and tradeoffsGrace Abraham
 
Microprocessor_Counter_and_Time_Delay.pptx
Microprocessor_Counter_and_Time_Delay.pptxMicroprocessor_Counter_and_Time_Delay.pptx
Microprocessor_Counter_and_Time_Delay.pptx
amritsaravagi
 
Pipelining slides
Pipelining slides Pipelining slides
Pipelining slides
PrasantaKumarDash2
 
Coa.ppt2
Coa.ppt2Coa.ppt2
AVRTIMER.pptx
AVRTIMER.pptxAVRTIMER.pptx
AVRTIMER.pptx
Pratik Gohel
 
6.pptx
6.pptx6.pptx
6.pptx
Chanyalew21
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
logesh waran
 
Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptx
AmoghR3
 
Divide by N clock
Divide by N clockDivide by N clock
Divide by N clock
Mantra VLSI
 
Timer programming
Timer programming Timer programming
Timer programming vijaydeepakg
 
Unit4_DE.pptx
Unit4_DE.pptxUnit4_DE.pptx
Unit4_DE.pptx
PriyankaJain98423
 
8051 timers--2
   8051 timers--2   8051 timers--2
8051 timers--2
Syed Basharat Hussain
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.ppt
HebaEng
 
Pipeline r014
Pipeline   r014Pipeline   r014
Pipeline r014
arunachalamr16
 

Similar to Chapter 8 (20)

8.1 Counters & Time Delays.pptx
8.1 Counters & Time Delays.pptx8.1 Counters & Time Delays.pptx
8.1 Counters & Time Delays.pptx
 
8085-Programming-II-mod-1.pptx
8085-Programming-II-mod-1.pptx8085-Programming-II-mod-1.pptx
8085-Programming-II-mod-1.pptx
 
Delay routine
Delay routineDelay routine
Delay routine
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
computer architecture 4
computer architecture 4 computer architecture 4
computer architecture 4
 
Timing & Control.pptx
Timing & Control.pptxTiming & Control.pptx
Timing & Control.pptx
 
Rtl design optimizations and tradeoffs
Rtl design optimizations and tradeoffsRtl design optimizations and tradeoffs
Rtl design optimizations and tradeoffs
 
Microprocessor_Counter_and_Time_Delay.pptx
Microprocessor_Counter_and_Time_Delay.pptxMicroprocessor_Counter_and_Time_Delay.pptx
Microprocessor_Counter_and_Time_Delay.pptx
 
Pipelining slides
Pipelining slides Pipelining slides
Pipelining slides
 
Coa.ppt2
Coa.ppt2Coa.ppt2
Coa.ppt2
 
AVRTIMER.pptx
AVRTIMER.pptxAVRTIMER.pptx
AVRTIMER.pptx
 
6.pptx
6.pptx6.pptx
6.pptx
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
 
Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptx
 
Divide by N clock
Divide by N clockDivide by N clock
Divide by N clock
 
Timer programming
Timer programming Timer programming
Timer programming
 
Unit4_DE.pptx
Unit4_DE.pptxUnit4_DE.pptx
Unit4_DE.pptx
 
8051 timers--2
   8051 timers--2   8051 timers--2
8051 timers--2
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.ppt
 
Pipeline r014
Pipeline   r014Pipeline   r014
Pipeline r014
 

More from deval patel

8085 interrupts
8085 interrupts8085 interrupts
8085 interrupts
deval patel
 
8254 PIT
8254 PIT8254 PIT
8254 PIT
deval patel
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
deval patel
 
8085 intro
8085 intro8085 intro
8085 intro
deval patel
 
8155 GPPI
8155 GPPI8155 GPPI
8155 GPPI
deval patel
 
8279 PKDI
8279 PKDI8279 PKDI
8279 PKDI
deval patel
 
8085 Microprocessor Architecture
8085 Microprocessor Architecture8085 Microprocessor Architecture
8085 Microprocessor Architecture
deval patel
 
8085 Architecture
8085 Architecture8085 Architecture
8085 Architecture
deval patel
 
Memory & I/O interfacing
Memory & I/O  interfacingMemory & I/O  interfacing
Memory & I/O interfacing
deval patel
 
Interrupts
InterruptsInterrupts
Interrupts
deval patel
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
deval patel
 

More from deval patel (11)

8085 interrupts
8085 interrupts8085 interrupts
8085 interrupts
 
8254 PIT
8254 PIT8254 PIT
8254 PIT
 
8255 PPI
8255 PPI8255 PPI
8255 PPI
 
8085 intro
8085 intro8085 intro
8085 intro
 
8155 GPPI
8155 GPPI8155 GPPI
8155 GPPI
 
8279 PKDI
8279 PKDI8279 PKDI
8279 PKDI
 
8085 Microprocessor Architecture
8085 Microprocessor Architecture8085 Microprocessor Architecture
8085 Microprocessor Architecture
 
8085 Architecture
8085 Architecture8085 Architecture
8085 Architecture
 
Memory & I/O interfacing
Memory & I/O  interfacingMemory & I/O  interfacing
Memory & I/O interfacing
 
Interrupts
InterruptsInterrupts
Interrupts
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 

Recently uploaded

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 

Recently uploaded (20)

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 

Chapter 8

  • 1. Chapter 8 Counters & Time Delays
  • 2. Counters & Time Delays • Counters are used for keep track of events like in For loop • Delays are used in setting up reasonably accurate timing between two events • Counters and time delays can be implemented either on – Software – Hardware • Both are implemented with Loop construct • What is appropriate for counter and Time Delay – Counts Time duration – Counts Number of iteration
  • 3. Counters • A loop counter is set up by loading a register with a certain value • Then using the DCR (to decrement) and INR (to increment) the contents of the register are updated. • A loop is set up with a conditional jump instruction that loops back or not depending on whether the count has reached the termination count.
  • 4. Counters • The operation of a loop counter can be described using the following flowchart. Initialize Update the count Is this Final Count? Body of loop No Yes
  • 5. Delays • It was shown in Chapter 2 that each instruction passes through different combinations of Fetch, Memory Read, and Memory Write cycles. • Knowing the combinations of cycles, one can calculate how long such an instruction would require to complete. • The table in Appendix F of the book contains a column with the title B/M/T. – B for Number of Bytes – M for Number of Machine Cycles – T for Number of T-State.
  • 6. Delays • Knowing how many T-States an instruction requires, and keeping in mind that a T-State is one clock cycle long, we can calculate the time using the following formula: Delay = No. of T-States / Frequency • For example a “MVI” instruction uses 7 T-States. Therefore, if the Microprocessor is running at 2 MHz, the instruction would require 3.5 µSeconds to complete.
  • 7. Delay loops • We can use a loop to produce a certain amount of time delay in a program. • The following is an example of a delay loop: MVI C, FFH 7 T-States LOOP DCR C 4 T-States JNZ LOOP 10 T-States • The first instruction initializes the loop counter and is executed only once requiring only 7 T-States. • The following two instructions form a loop that requires 14 T- States to execute and is repeated 255 times until C becomes 0.
  • 8. Delay Loops (Contd.) • We need to keep in mind though that in the last iteration of the loop, the JNZ instruction will fail and require only 7 T-States rather than the 10. • Therefore, we must deduct 3 T-States from the total delay to get an accurate delay calculation. • To calculate the delay, we use the following formula: Tdelay = TO + TL – Tdelay = total delay – TO = delay outside the loop – TL = delay of the loop • TO is the sum of all delays outside the loop. • TL is calculated using the formula TL = T X Loop T-States X N10
  • 9. Delay Loops (Contd.) • Using these formulas, we can calculate the time delay for the previous example: • TO = 7 T-States – Delay of the MVI instruction • TL = (14 X 255) - 3 = 3567 T-States – 14 T-States for the 2 instructions repeated 255 times (FF16 = 25510) reduced by the 3 T-States for the final JNZ. • TDelay = (7 + 3567) X 0.5 µSec = 1.787 mSec – Assuming f = 2 MHz
  • 10. Using a Register Pair as a Loop Counter • Using a single register, one can repeat a loop for a maximum count of 255 times. • It is possible to increase this count by using a register pair for the loop counter instead of the single register. – A minor problem arises in how to test for the final count since DCX and INX do not modify the flags. – However, if the loop is looking for when the count becomes zero, we can use a small trick by ORing the two registers in the pair and then checking the zero flag.
  • 11. Using a Register Pair as a Loop Counter • The following is an example of a delay loop set up with a register pair as the loop counter. LXI B, 1000H 10 T-States LOOP DCX B 6 T-States MOV A, C 4 T-States ORA B 4 T-States JNZ LOOP 10 T-States
  • 12. Using a Register Pair as a Loop Counter • Using the same formula from before, we can calculate: • TO = 10 T-States – The delay for the LXI instruction • TL = (24 X 4096) - 3 = 98301 T- States – 24 T-States for the 4 instructions in the loop repeated 4096 times (100016 = 409610) reduced by the 3 T-States for the JNZ in the last iteration. • TDelay = (10 + 98301) X 0.5 mSec = 49.155 mSec
  • 13. Nested Loops • Nested loops can be easily setup in Assembly language by using two registers for the two loop counters and updating the right register in the right loop. – In the figure, the body of loop2 can be before or after loop1. Initialize loop 1 Update the count1 Is this Final Count? Body of loop 1 No Yes Initialize loop 2 Body of loop 2 Update the count 2 Is this Final Count? No Yes
  • 14. Nested Loops for Delay • Instead (or in conjunction with) Register Pairs, a nested loop structure can be used to increase the total delay produced. MVI B, 10H 7 T-States LOOP2 MVI C, FFH 7 T-States LOOP1 DCR C 4 T-States JNZ LOOP1 10 T-States DCR B 4 T-States JNZ LOOP2 10 T-States
  • 15. Delay Calculation of Nested Loops • The calculation remains the same except that it the formula must be applied recursively to each loop. – Start with the inner loop, then plug that delay in the calculation of the outer loop. • Delay of inner loop – TO1 = 7 T-States • MVI C, FFH instruction – TL1 = (255 X 14) - 3 = 3567 T-States • 14 T-States for the DCR C and JNZ instructions repeated 255 times (FF16 = 25510) minus 3 for the final JNZ. – TLOOP1 = 7 + 3567 = 3574 T-States
  • 16. Delay Calculation of Nested Loops • Delay of outer loop – TO2 = 7 T-States • MVI B, 10H instruction – TL1 = (16 X (14 + 3574)) - 3 = 57405 T-States • 14 T-States for the DCR B and JNZ instructions and 3574 T-States for loop1 repeated 16 times (1016 = 1610) minus 3 for the final JNZ. – TDelay = 7 + 57405 = 57412 T-States • Total Delay – TDelay = 57412 X 0.5 µSec = 28.706 mSec
  • 17. Increasing the delay • The delay can be further increased by using register pairs for each of the loop counters in the nested loops setup. • It can also be increased by adding dummy instructions (like NOP) in the body of the loop.