Bubble Sort in Assembly Language

include irvine32.inc

.data
array byte 10 DUP(?)
swap byte 0
msg byte " Enter 10 NUmber: ",0
msg1 byte " After Sorting : ",0
msg2 byte "   ",0

.code
main proc
call clrscr
call crlf
mov edx,offset msg
call writestring
call crlf
mov edx,offset array
mov ecx,lengthof array
mov esi,0

L1:
call readint
mov array[esi],al
inc esi
loop L1

mov bx,1
mov ax,8

mov edx,offset array

.while bx > 0
mov bx,0
mov si,0



.while si <= ax

mov al,array[si+1]
.if array[si] > al




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

mov bx,si

.endif
inc si

.endw
mov ax,bx


.endw

mov edx,offset array
mov ecx,lengthof array
mov esi,0
mov edx,offset msg1
call writestring
L2:
mov al,array[esi]
call writedec
mov edx,offset msg2
call writestring
inc esi
loop L2

exit
main endp
end main


0 comments:

Post a Comment

My Instagram