冒泡排序
include io.inc
.model small
.stack
.data
array dw 587,-632,777,234,-34 ;假设一个数组
count = lengthof array ;数组的元素个数
.code
.startup
mov cx,count ;CX←数组元素个数
dec cx ;元素个数减1为外循环次数
outlp: mov dx,cx ;DX←内循环次数
mov bx,offset array
inlp: mov ax,[bx] ;取前一个元素
cmp ax,[bx+2] ;与后一个元素比较
jng next
;前一个不大于后一个元素,则不进行交换
xchg ax,[bx+2] ;否则,进行交换
mov [bx],ax
next: add bx,2 ;下一对元素
dec dx
jnz inlp ;内循环尾
loop outlp ;外循环尾
mov cx,count
mov si,offset array
output:mov ax,[si]
call dispsiw ;输出
add si,type array
call dispcrlf ;换行
loop output
.exit
end