Skip to content

Instantly share code, notes, and snippets.

@tanayseven
Created October 9, 2012 16:32
Show Gist options
  • Select an option

  • Save tanayseven/3859907 to your computer and use it in GitHub Desktop.

Select an option

Save tanayseven/3859907 to your computer and use it in GitHub Desktop.
Bubble sort using Procedures in 8086 asm lang.
; Bubble sort using Procedures
include io.h
cr equ 0dh
lf equ 0ah
data segment
l1 db cr,lf,'Enter n: ',0
l2 db cr,lf,'Enter the array: ',0
l3 db cr,lf,'The sorted array in descending orde using Bubble sort is: ',0
l4 db cr,lf,0
n dw ?
temp dw ?
i dw ?
value dw 40 dup (?)
array dw 40 dup (?)
data ends
code segment
assume cs:code,ds:data
BUBBLE PROC NEAR
mov ax,1
mov i,ax
outer_for:
lea si,array
mov dx,n
for1: mov ax,[si]
add si,2
mov bx,[si]
cmp ax,bx
jg for3
for2: mov temp,ax
mov ax,bx
mov bx,temp
mov [si],bx
sub si,2
mov [si],ax
add si,2
for3: dec dx
cmp dx,i
jne for1
inc i
mov cx,i
cmp cx,n
jne outer_for
RET
BUBBLE ENDP
start: mov ax,data
mov ds,ax
output l1
inputs value,40
atoi value
mov n,ax
lea si,array
mov dx,n
output l2
input_the_array: inputs value,40
atoi value
mov [si],ax
add si,2
dec dx
jnz input_the_array
CALL BUBBLE
output l3
output l4
lea si,array
mov dx,n
output_the_array: itoa value,[si]
output value
add si,2
dec dx
jnz output_the_array
quit: mov al,00
mov ah,4ch
int 21h
code ends
end start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment