Programming of 8086: M.A.Himayath Shamshi Assco - Prof Dept of ECE Vaagdevi College of Engineering
Programming of 8086: M.A.Himayath Shamshi Assco - Prof Dept of ECE Vaagdevi College of Engineering
M.A.Himayath Shamshi
Assco.Prof
Dept of ECE
Vaagdevi college of Engineering
1 / 30
2 / 30
3 / 30
4 / 30
5 / 30
6 / 30
7 / 30
Program 13: Multiply two 8-bit unsigned numbers.
MOV AX,2000H
MOV DS, AX
MOV SI,0100H
MOV CX,64H
MOV AL,00H
L1: INC AL
MOV[SI],AL
DEC CX
JNZ: L1
INTA5
RESULT 2000h:0100h 01h
0101h 02h
0102h 03h
0103h 04h
0104H 05h 24 / 30
:
Program to Count the no: of 1’s in a given number
MOVAL,99H
MOVCL,08H
MOVBL,00H
L2: RCLAL,01H
JNC: L1
INC BL
L1:DEC CL
JNZ:L2
INTA5
25 / 30
Program to Display Fibonacci series
MOV AX,0000H
MOV DS,AX
MOV SI,0400H
MOV AL,00H
MOV[SI],AL
MOV BL,01H
MOV CL,08H
INC SI
MOV[SI],BL
L1:ADD AL,BL RESULT 0000H:0400H 00H
INC SI :0401H 01H
MOV[SI],AL :0402H 01H
XCHG AL,BL :0403H 02H
DEC CL :0404H 03H
JNZ: L1 :0405H 05H26 / 30
MOVAX,0000H
MOV DC,AX
MOV SI,0400H
MOV DI,0500H
MOV CL,0AH
L1:MOV AL,[SI]
MOV [DI],AL
INC SI MOVAX,0000H
INC DI MOVES,AX
DEC CL MOV SI,0400H
JNZ: L1 MOV DI,0500H
INTA5 MOV CL,0AH
CLD
REP: MOVSB 27 / 30
INTA5
Time Delay Programs of 8086
➢
Every instruction in the 8086 requires a definite number of clock cycles for its
execution. The amount of time for execution of an instruction is obtained by
multiplying the number of clock cycles required for the execution the
instruction, with the clock period at which the 8086 is running.
➢
The steps for writing a time delay program are as follows:
➢
(i) Find the exact time delay (td) required for the given application.
➢
(ii) Select the instructions to be included in the time delay program. While selecting the
instructions and registers to be used in the delay program, care must be taken that the
execution of these instructions does-not affect the main program execution. That is, any
memory location or register used by the main program must not be altered by time delay
program. If a register used in the main program is needed in the delay program, the
content of that register is pushed into a stack before executing the time delay program. At
the end of the execution of the time program, its original value will be popped from the
stack and then control will be transferred to the main program.
➢
(iii) Find the period of the clock at which the microprocessor is running by taking the
reciprocal of the 8086’s clock frequency. T is the duration of one clock period of clock
state.
➢
(iv) Find the number of clock states required for execution of each of the instructions in
the time-delay program. Then find the number of clock states (m) needed to execute the
loop in the delay program once, by adding the clock states required for each instruction in
the delay program.
➢
(v) Find the number of times (i.e., count n) the loop in the delay program has to be
28 / 30
executed by dividing the required time delay (td) by the time taken to execute the loop
once, which is m X T Count (n) = td/ (m X T) The time delay obtained using this method
➢
Write a time delay program to generate a delay of 120ms in an 8086 – based
system that runs on a 10Mhz frequency clock.
Solution: The time delay program is as follows:
Instructions T- States for execution
MOV BX,Count 4
L1: DEC BX 2
NOP 3
JNZ : L1 16
RET 8
➢
In this program, the instructions DEC BX, NOP, and JNZ L1 form the loop as they
are executed repeatedly until BX becomes zero. Once BX becomes zero, the 8086
returns to the main program.
➢
Number of clock cycles for execution of the loop once (m) = 2 + 3 + 16 = 21
➢
Time required for the execution of loop once = m X T = 21 X 1/(10 X 10^6) = 2.1
µs Count = td/(m X T) = 120 X 10^-3 /(2.1 X 10^-6) = 57143 = DF37h 29 / 30
➢
By loading DF37h in BX, the time taken to execute the delay program is
➢
The NOP included in the delay program is to increase the execution time of
the loop.
➢
To get more delay, the number of NOP instructions in the delay loop can be
increased.
➢
The exact delay obtained using this time delay subroutine can be calculated
as
➢
The MOV BX, Count & RET instructions in the delay program are
executed only once.
➢
The JNZ instruction takes 16 T-states
➢
when the condition is satisfied (i.e. Z = 0) and four T – states
➢
when the condition is not satisfied, which occurs only once.
➢
Exact delay = [4 x 0.1 + (2+3) x 57143 x 0.1 + 16 x 57142 x0.1 + 4 X 0.1 +
8 X 0.1 ] µs = 0.4 + 28571.5 + 91427.2 + 0.4 + 0.8 = 120000.3 µs =
120.0003 ms
➢
When 16-bit count register is used in the delay program, the maximum
count value that can be loaded in it is FFFFh.
➢
This may put a limitation on the maximum time delay that can be generated
using the above delay subroutine.
30 / 30