Description: A simple bubble sort assembly code that sorts
an unsorted array using bubble sort.
[org 0x0100]
mov ax , 0
mov bx , 0
mov cx , [size]
add cx , [size]
sub cx , 2
mov dx , 0
mov si , 0
mov di , 0
outerLoop:
cmp si , cx
jnl exit
mov dx , [size]
add dx , [size]
sub dx , si
sub dx
,2
mov di , 0
bubbleLoop:
mov ax , [arr+di]
mov bx , [arr+di+2]
cmp ax , bx
jg swap
return:
add word di , 2
cmp di , dx
jl bubbleLoop
incSI:
inc si;
inc si
jmp outerLoop
swap:
mov [arr+di] , bx
mov [arr+di+2] , ax
jmp return
exit:
mov ax , 0x4c00
int 0x21
size: dw 15
arr: dw 14,3,1,6,15,10,5,11,4,8,13,2,12,9,7
No comments
Post a Comment