Code:
; PROGRAM TO ARRANGE NUMBERS OF THE ARRAY IN DESCENDING ORDER
.MODEL SMALL
.STACK 100H
.DATA
ARR DB 8,9,2,7,5
.CODE
MOV AX , @DATA ; INITIALIZING DATA SEGMENT
MOV DS , AX
;PRINTING CONTAIN OF ARRAY BEFORE SORTING
MOV CX , 5
LEA SI , ARR
L1:
MOV DL , [SI]
ADD DL , 48
MOV AH , 02
INT 21H
INC SI
LOOP L1
MOV BX , 5 ; SET PASS COUNTER
NEXTPASS:
LEA SI , ARR ; LOADING EFFECTIVE ADDRESS OF ARR
MOV CX , 4 ; INITIALIZING COUNTER
NEXT:
MOV AL , [SI] ; STORING NUMBER FROM ARRAY
CMP AL , [SI+1] ; IF DESTINATION > SOURCE THEN CF =0
; IF DESTINATION < SOURCE THEN CF =1
JNC UP ; JUMP IF NOT CARRY
XCHG AL , [SI+1]
XCHG AL , [SI]
UP:
INC SI
LOOP UP
DEC BX
JNZ NEXTPASS ; JUMP IF NOT ZERO
; PRINTING NEWLINE
MOV AH , 2
MOV DL , 0DH ;CARGE RETURN
INT 21H
MOV DL , 0AH ;LINE FEED
INT 21H
;PRINTING CONTAIN OF ARRAY AFTER SORTING
MOV CX , 5
LEA SI , ARR
L2:
MOV DL , [SI]
ADD DL , 48
MOV AH , 02
INT 21H
INC SI
LOOP L2
MOV AH , 4CH ; SERVICE ROUTINE TO EXIT
INT 21H
END
; PROGRAM TO ARRANGE NUMBERS OF THE ARRAY IN DESCENDING ORDER
.MODEL SMALL
.STACK 100H
.DATA
ARR DB 8,9,2,7,5
.CODE
MOV AX , @DATA ; INITIALIZING DATA SEGMENT
MOV DS , AX
;PRINTING CONTAIN OF ARRAY BEFORE SORTING
MOV CX , 5
LEA SI , ARR
L1:
MOV DL , [SI]
ADD DL , 48
MOV AH , 02
INT 21H
INC SI
LOOP L1
MOV BX , 5 ; SET PASS COUNTER
NEXTPASS:
LEA SI , ARR ; LOADING EFFECTIVE ADDRESS OF ARR
MOV CX , 4 ; INITIALIZING COUNTER
NEXT:
MOV AL , [SI] ; STORING NUMBER FROM ARRAY
CMP AL , [SI+1] ; IF DESTINATION > SOURCE THEN CF =0
; IF DESTINATION < SOURCE THEN CF =1
JNC UP ; JUMP IF NOT CARRY
XCHG AL , [SI+1]
XCHG AL , [SI]
UP:
INC SI
LOOP UP
DEC BX
JNZ NEXTPASS ; JUMP IF NOT ZERO
; PRINTING NEWLINE
MOV AH , 2
MOV DL , 0DH ;CARGE RETURN
INT 21H
MOV DL , 0AH ;LINE FEED
INT 21H
;PRINTING CONTAIN OF ARRAY AFTER SORTING
MOV CX , 5
LEA SI , ARR
L2:
MOV DL , [SI]
ADD DL , 48
MOV AH , 02
INT 21H
INC SI
LOOP L2
MOV AH , 4CH ; SERVICE ROUTINE TO EXIT
INT 21H
END