Exp 04 Ascending & Descending Order
Exp 04 Ascending & Descending Order
23EC2106R
PROCESSORS AND CONTROLLERS
Lab Experiment - 4
Aim
Theory:
• Write a paragraph about control transfer instructions in 8086 microprocessor.
Exp 4: Ascending & Descending order using 8086
Input Data:
• The 16 bytes of data stored in offset location 0200H of segment
location 7000H is
37H, 53H, 2BH, A1H,
42H, 20H, 61H, 71H,
0CH, 91H, 15H, BFH,
27H, D0H, EFH, 4CH
Exp 4: Ascending & Descending order using 8086
Program Table: (a) Ascending Order
Address Program Comment
0100:0000 MOV AX, 5000H Move the value 2000H into AX register (loading segment address)
0100:0003 MOV DS, AX Move the contents of AX into DS register (data segment register)
0100:0005 MOV CL, 0FH Load CL register with the number of iterations (0FH or decimal 15)
0100:0007 BACK1: MOV DL, CL Load DL register with the number of iterations (0FH or decimal 15)
0100:0009 MOV SI, 0400H loading the source data offset address into SI register
0100:000C MOV AL, [SI] Move the data from source address into AL register
0100:000E BACK2: INC SI Increase the source data offset address by 1
0100:000F CMP AL, [SI] Compare the contents of AL register with the contents of SI location
0100:0011 JC NEXT If CF=1, jump to NEXT address (that is if carry generated, second number is
larger than first number)
0100:0013 XCHG AL, [SI] If CF=0, exchange the data from source address and AL register (that is if carry
not generated, first number is larger than second number)
0100:0015 XCHG AL, [SI-1] exchange the data from source address-1 and AL register
Exp 4: Ascending & Descending order using 8086
Program Table: (a) Ascending Order (continuation)
Address Program Comment
0100:0018 NEXT: MOV AL, [SI] If CF=1, load the data from source address into AL register (that is if CF=1, the
numbers are in correct order but second number should be in AL)
0100:001A DEC DL Decrease DL contents by 1
0100:001C JNZ BACK2 If ZF=0, jump to BACK2 address (that is if count (DL) is not zero, repeat the
process from BACK2 address)
0100:001E DEC CL Decrease CL contents by 1
0100:0020 JNZ BACK1 If ZF=0, jump to BACK1 address (that is if count (CL) is not zero, repeat the
process from BACK1 address)
0100:0022 HLT Halt (stop) the processor.
Exp 4: Ascending & Descending order using 8086
Write result on your own based on aim (refer first 3 experiment’s results and aims)
THANK YOU
N L PRASAD