Google Search

Wednesday, October 27, 2010

SORTING THE NUMBERS IN DESCENDING ORDER To write an assembly language program to sort the numbers in descending order using 8086 microprocessor.

ALGORITHM:
1. Start the process
2. Move the data to CX register and move CX content to D1 register
3. Move the address to BX register and move the count of 2200 to AX
4. Compare the content of AX with 2202`
5. Jump on no borrow to REP
6. Exchange AX and A1 register and move AX register to BX
7. Add BX register to 2 and continue the loop up to CX is zero
8. Perform no operation and move D1 register to CX register and continue the loop up to CX is zero
9. Stop the program
PROGRAM:
ADDRESS LABEL OPCODE MNEMONICS OPERAND COMMENTS
2000 B9, 07, 00 MOV CX, 07 Move data to CX reg
2003 LOOP1 89 CF MOV DI, CX Move CX data to DI reg
2005 BB, 00, 22 MOV BX, 2200 Move 2200 to the BX reg
2008 LOOP2 8B, 07 MOV AX, AI [BX] Move the content of 2200 to memory of AX
200A 3B, 47, 02 CMP AX,AI[BX+2] Compare the content of AX with 2202
200D 73, 05 JNB REP Jump on borrow to rep
200F 87, 47, 02 XCHG AX,AI[BX+2] Move the data in memory to AX
2012 89, 07 MOV AI [BX], AX Move data from AX to AI
201A REP 83, C3, 02 ADD BX,2 Add data to BX register
2017 F2, EF LOOP LOOP2 Go to loop2
2019 90 NOP No operation
201A 89, F9 MOV CX,DI Move data of DI to CX
201C E2, E5 LOOP LOOP1 Go to loop1
201E F4 HLT Stop the process

DESCENDING ORDER
INPUT:
1200 – 0002 1208 - 0078
1202 – 0006 120A - 0012
1204 – 00A1 120C - 0011
1206 – 00C2
OUTPUT:

1200 – 00C2 1208 - 0011
1202 – 00A1 120A - 0006
1204 – 0078 120C - 0002
1206 - 0012

0 comments:

Post a Comment