Bubble Sorting in Assembly Language 8086 | Array Sorting

Bubble Sorting program in assembly language on emulator 8086.

Steps:

1- Declare an Array

2- Set all elements to 0

3- Take 10 inputs in the array

4- Start a loop of 10 itteration

5- Compare index 0 to index 1

6- Swap elements if index 1 is greater

7- Iterate the Loop 10 times

8-Print the Sorted Array

 

 

Bubble Sort program in assembly language

Bubble Sort

org 100h

.data

str db 10,13,”Enter Values: $”
str1 db 0dh,0ah,”Bubble Sorted: $”
array db 10dup(0)

.code

mov ah,9
lea dx,str
int 21h

mov cx,10
mov bx,offset array
mov ah,1

inputs:
int 21h
mov [bx],al
inc bx
Loop inputs

mov cx,10
dec cx

nextscan:
mov bx,cx
mov si,0

nextcomp:
mov al,array[si] mov dl,array[si+1] cmp al,dl

jc noswap

mov array[si],dl
mov array[si+1],al

noswap:
inc si
dec bx
jnz nextcomp

loop nextscan

 

mov ah,9
lea dx,str1
int 21h

mov cx,10
mov bx,offset array

; this loop to display elements on the screen
print:
mov ah,2
mov dl,[bx] int 21h
inc bx
loop print

ret

Output Screen: 

 

Bubble Sort Output

 

One Comment

Add a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.