Monday, April 4, 2011

Program to sort the numbers in DEscending order


        MVI B, 09H   ; SIZE OF ARRAY
START   LXI H, 2000H ; INITIALIZE MEMORY POINTER
MVI C, 09H   ; INNER LOOP COMPARE ONE TERM WITH 9 TERMS
BACK MOV A, M     ; GET NUMBER IN ACCUMULATOR
INX H     ; INCREMENT MEMORY POINTER
CMP M     ; COMPARE
JNC SKIP     ; IF A>M DONT INTERCHANGE
JZ SKIP     ; IF A=M DONT INTERCHANGE
MOV D, M     ; OTHERWISE SWAP
MOV M, A     ;
DCX H        ; INTERCHANGE NUMBERS
MOV M, D     ; 
INX H        ; INCREMENT TO NEXT MEMORY
SKIP DCR C     ; DCR C
JNZ BACK     ; TILL C!=0 CONTINUE
DCR B     ; DCREMENT OUTSIDE COUNTER
JNZ START    ; TILL B!=0
HLT     ;

No comments:

Post a Comment