8086 Assembly Program to Sort Numbers in Ascending 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
JC 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 AMPE10.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987.  All rights reserved.

Object filename [AMPE10.OBJ]:
Source listing  [NUL.LST]:
Cross-reference [NUL.CRF]:

  49452 + 414900 Bytes symbol space free

      0 Warning Errors
      0 Severe  Errors

C:\TASM>link AMPE10.obj

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

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

C:\TASM>debug AMPE10.exe
-g

AX=1456  BX=0099  CX=0000  DX=0045  SP=0000  BP=0000  SI=0004  DI=0000
DS=14A4  ES=1494  SS=14A4  CS=14A5  IP=0027   NV UP EI PL ZR NA PE CY
14A5:0027 CC            INT     3
-d 14A4:0000
14A4:0000  12 36 45 56 99 00 00 00-00 00 00 00 00 00 00 00   .6EV............
14A4:0010  B8 A4 14 8E D8 B5 04 B1-04 8D 36 00 00 8A 04 8A   ..........6.....
14A4:0020  5C 01 3A C3 72 08 8A 54-01 86 14 88 54 01 46 FE   \.:.r..T....T.F.
14A4:0030  C9 75 EA FE CD 75 E0 CC-2B C0 8B F0 0B F6 74 0C   .u...u..+.....t.
14A4:0040  8B DE D1 E3 03 1E 9A 16-8B 07 EB 02 2B C0 89 46   ............+..F
14A4:0050  F2 C4 5E F8 26 8B 47 08-89 46 F6 8B 5E 06 8B 07   ..^.&.G..F..^...
14A4:0060  8B 57 02 89 46 F8 89 56-FA C4 5E F8 26 83 7F 06   .W..F..V..^.&...
14A4:0070  00 74 0F 26 8B 5F 06 D1-E3 03 1E 96 16 8B 07 EB   .t.&._..........

2 thoughts on “8086 Assembly Program to Sort Numbers in Ascending Order”

Leave a Reply

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