8086 Assembly Program to Sort Numbers in Descending Order

DATA SEGMENT
STRING1 DB 99H,12H,56H,45H,36H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV CH,04H
UP2: MOV CL,04H
LEA SI,STRING1

UP1:MOV AL,[SI]
MOV BL,[SI+1]
CMP AL,BL
JNC DOWN
MOV DL,[SI+1]
XCHG [SI],DL
MOV [SI+1],DL

DOWN: INC SI
DEC CL
JNZ UP1
DEC CH
JNZ UP2
INT 3
CODE ENDS
END START

Output

C:\TASM>masm str_desc.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987.  All rights reserved.

Object filename [str_desc.OBJ]:
Source listing  [NUL.LST]:
Cross-reference [NUL.CRF]:
str_desc.asm(1): warning A4001: Extra characters on line

  50760 + 450936 Bytes symbol space free

      1 Warning Errors
      0 Severe  Errors

C:\TASM>link str_desc.obj

Microsoft (R) Overlay Linker  Version 3.60
Copyright (C) Microsoft Corp 1983-1987.  All rights reserved.

Run File [STR_DESC.EXE]:
List File [NUL.MAP]:
Libraries [.LIB]:
LINK : warning L4021: no stack segment

C:\TASM>debug str_desc.exe
-g

AX=0B36  BX=0012  CX=0000  DX=0012  SP=0000  BP=0000  SI=0004  DI=0000
DS=0B37  ES=0B27  SS=0B37  CS=0B38  IP=0027   NV UP EI PL ZR NA PE NC
0B38:0027 CC            INT     3
-d 0B37:0000
0B37:0000  99 56 45 36 12 00 00 00-00 00 00 00 00 00 00 00   .VE6............
0B37:0010  B8 37 0B 8E D8 B5 04 B1-04 8D 36 00 00 8A 04 8A   .7........6.....
0B37:0020  5C 01 3A C3 73 08 8A 54-01 86 14 88 54 01 46 FE   \.:.s..T....T.F.
0B37:0030  C9 75 EA FE CD 75 E0 CC-0C 2A E4 40 50 8B C3 05   .u...u...*.@P...
0B37:0040  0C 00 52 50 E8 19 46 83-C4 04 50 8D 86 00 FF 50   ..RP..F...P....P
0B37:0050  E8 6F 70 83 C4 06 B8 CD-05 50 8D 86 00 FF 50 E8   .op......P....P.
0B37:0060  CA 0C 83 C4 04 B8 FF FF-50 8D 86 00 FF 50 8D 46   ........P....P.F
0B37:0070  80 50 E8 4D FA 83 C4 06-0A C0 75 03 E9 7B FF 5E   .P.M......u..{.^
-q

One thought on “8086 Assembly Program to Sort Numbers in Descending Order”

Leave a Reply

Your email address will not be published. Required fields are marked *