Descending sort in Assembly – masm 8086

Descending sort in Assembly – masm 8086

;It is a simple sorting algorithm that
;repeatedly steps through the list to
;be sorted, compares each pair of adjacent
;items and swaps them if they are in the
;wrong order. The pass through the list
;is repeated until no swaps are needed,
;which indicates that the list is sorted.
;Although the algorithm is simple,
org 100h
.model small
.data
ARR DB 1,2,3,4,5,6,7,8,9,10
arr_size = $ - offset ARR
counter Dw 0
j dw 0
.code
;Initilize Data Segment
mov ax,@DATA
mov DS,ax
mov si,offset arr
mov bl,arr_size
mov cl,bl
mov ch,00h
mov counter,arr_size
L1:
mov cl,arr_size
dec cl
mov ch,00h
lea si,arr
L2:
mov ah,[si]
inc si
mov al,[si]
cmp ah,al
jge next
mov [si],ah
dec si
mov [si],al
inc si
next:
LOOP L2
inc j
mov cx,counter
dec counter
LOOP L1
;to terminate program
mov ah,4ch
int 21h
ret

Advertisements

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