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     ;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s