We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Microprocessors and Interfacing 3-72 8086 Instruction Set and ALP
INZ BA ; If not 0 go to back
END
It is important to note that programs discussed so far do not accept any input from
keyboard and do not display any result on the video screen. This is done purposely to
maintain simplicity. To aecept input in various formats from keyboard and to display data
on the video screen we have to use routines provided by Disk Operating System (DOS).
These routines are discussed in Chapter 9. The programs given in the subsequent sections
use routines provided by DOS. Therefore, students are suggested to refer these routines
before further reading the remaining part of this text.
3.15 Timings and Delays
In the real time applications, such as traffic light control, digital clock, process control,
serial communication, it is important to keep a track with time. For example in traffic light
control application, it is necessary to give time delays between two transitions. These time
delays are in few soconds and can be generated the help of executing group of
instructions number of times, This software timers are also called time delays or software
delays. Let us see how to implement these time delays or software delays.
As you know microprocessor system consists of two basic components, hardware and
software. The software component controls and operates the hardware to get the desired
output with the help of instructions. To execute these instructions, microprocessor takes fix
time as per the instruction, since it is driven by constant frequency clock. This makes it
possible to introduce delay for specific time between two events. In the following section
we will see different delay implementation techniques.
3.15.1 Timer Delay using NOP Instruction
NOP instruction does nothing but takes 3 clock cycles of processor time to execute. So
by executing NOP instruction in between two instructions we can get delay of 3 clock
cycles,
3.15.2 Timer Delay using Counters
Counting can create time delays. Since the execution times of the instructions used in a
counting routine are known, the initial value of the counter, required to get specific time
delay can be determined.
Clock cycles required
MOV CX, COUNT 7 Load count 4
BACK : DEC CX + Decrement count 2
ONZ BACK } Tf count # 0, repeat 16/4
In this program, the instructions DEC CX and JNZ BACK execute number of times
equal to count stored in the CX register. The time taken by this program for execution can
be calculated with the help of clock cycles. The column to the right of the comments
indicates the number of clock cycles required for the execution of each instruction. Two
values are specified for the number of clock cycles for the JNZ instruction. The smallerMicroprocessors and Interfacing 3-73 8086 Instruction Set and ALP
value is applied when the condition is not met, and the larger value is applied when it is
met. The first instruction MOV CX, count is executed only once and it requires 4 clock
eyeles. There are count-1 passes through the loop where the condition is met and control
is transferred back to the first instruction in the loop (DEC CX). The number of clock
cycles that elapse while CX register is not zero are (count-1) x (2 + 16). On the last pass
through the loop the condition is not met and the loop is terminated. The number of clock
cycles that elapse in this pass are 2 + 4.
. Total clock cycles required to execute the given program
= 4 +(Count ~1)x(2+16)+(2+4)
MOVER Cant Tgp" Sati
For count = 100, the number of clock cycles required are
= 4+ (100-1) (2 16) + (2+ 4)
= 1792
Assuming operating frequency of 8086 system 10 MHz,
Time required for 1 clock-cycle = = 0.1 psec
1
10MHiz
<. Total time required for execution of a given program with count equal to 100 is
179.2 sec (1792 x 0.1).
In the above example, we have calculated the time required for the execution of
program or delay introduced by the program when count value is given, However, in
most of the situations we know the waiting time or delay time and it is necessary to
determine what count should be loaded in the CX register to get the specified delay. Let
us consider that we have to generate a delay of 50 ms using an 8086 system that runs at
10 MHz frequency, Then using same program we can calculate the count value as follows
Step 1: Calculate the number of required clock cycles
Required delay time
Time for 1- clock cycle
50 ms
= Ope 7 500 000
Number of required clock cycles =
Step 2 : Find the required count
Number of required clock cycles~4~(2+4) |
“Execution Time for one loop
_ 00000-4-6 | |
~ (i6+2)
Count =
= 27778 = 6C82HMicroprocessors and interfacing 3-74 8086 Instruction Set and ALP
3.15.3 Timer Delay using Nested Loops
In this program one more extemal loop is added to execute the internal loop multiple
times. So that we can get larger delays. The inner loop is nothing but the program we
have scen in the last section.
MOV BX, Multiplier count Load multiplier count
REPE : MOV CX, COUNT } Load count
BACK : DEC CX } Decrement count
JNZ BACK + If count # 0, repeat
DEC Bx ; Decrement multiplier count
JN2 REPE ? If not zero repeat
In the delay calculations of nested loops, the delay introduced by inner loop is very
large in comparison the delay provided by MOV BX, COUNT, DEC BX and JNZ
instructions. Therefore, it is not necessary to consider the last loop for the external loop
delay calculations separately. The inner loop delay calculations will remain as it is,
2 Total clock cycles required to execute the given program
=[ 4 +(count-1)x(2+16) + (2+4)] x multiplier count
MOV CX, Count Loop Last hop
For count = 100 and multiplier count 50, the number of clock
cycles required are
= [4+ (100 - 1) x (2 + 16) + (2 + 4)} x 50
= 89600
Assuming operating frequency of 8086 system 10 MHz,
Total time required for execution of a given program
= 89600 x 0.1 psec = 8.96 ms
tm Example 2: Write an 8086 ALP ta generate a delay of 100 ms, if 8086 system frequency
is 10 MHz.
Solution :
Program :
MOV Cx, COUNT 7 4
BACK : DEC CX #2
JNZ BACK + 16/4
Step 1: Calculate the number of required clock cycles
Required delay time
Number of required clock cycles = te Fort clock epels
100 ms
= Digs 7 1000 000Microprocessors and Interfacing 3-75 8086 Instruction Set and ALP
Step 2: Find the required count
Number of required clock cycles—4~(2-44) |
Coot = Execution ime for one loop
1
= looo000-4-6 | ,
~ Tee
= 55556 = D904H
> Example 3: Write an 8086 ALP to generate a delay of 1 minute if 8086 system frequency
is 10 MHz.
Solution :
Program
MOV BX, multiplier count
REP! MOV CX, Count a4
BACK DEC Cx #2
JNZ BACK a 16/4
DEC BX
JNZ REPE
Step 1: Calculate the delay generated by inner loop with maximum count (FFFFH)
Delay generated by inner loop for count (FFFFH = 65535)
[4 + (65535 ~ 1) x (2 + 16) + (2 + 4)] x O.1 ps
= 1181422 msee
Step 2: Calculate the multiplier count to get delay of 1 minute
Required delay
‘Delay provided by inner loop
_ _1x60sec
~ -T18-1422 msec
multiplier count =
= 509 = 1FDH
3.16 Data Conversions
Before going to write and execute any assembly language program on a computer we
must understand which type of data processor understands and which type of data user
understands, and how they communicate with each other. User communicates with
computer using input devices and computer gives outcome of process or result on the
display devices or hardcopy devices such as printer or plotter. Most commonly used input
device is keyboard and most commonly used output device is a display device, video
monitor. These devices understand the information in ASCII format. Keyboard gives the
pressed key number or character in its ASCII equivalent and for display certain number or
character we have to send the ASCII equivalent of the number or character to the display