You are on page 1of 2

EXP. NO.

9 SORTING OF NUMBERS

AIM:
To sort the given numbers in either ascending or descending order.
APPARATUS REQUIRED:
Keil software

ALGORITHM:
1. Start.
2. Store the values starting from location, say 40H.
3. Initially store the first value in a register.
4. Compare next values with the register.
5. If the compared value is smaller/larger, replace the number in register with the
new value.
6. End.

PROGRAM:
ORG 0H

X EQU 40H

COUNT EQU 4H

MOV R1,#COUNT

L4: MOV R0,#X

MOV R2,#COUNT

L3: MOV A,@R0

INC R0

CLR C

SUBB A,@R0

JNC L2

ADD A,@R0
XCH A,@R0

DEC R0

MOV @R0,A

INC R0

L2: DJNZ R2,L3

DJNZ R1,L4

L5: SJMP L5

END
OUTPUT:

INFERENCE:
We have sorted the given numbers in descending order by comparing continuously
with a set value in a register. The mnemonics used are XCH, DJNZ, SJMP, JNC.
Replace JNC by JC to sort in ascending order.

RESULT:
The given set of numbers has been sorted and verified successfully.

You might also like