汇编 冒泡排序算法 求助

.data
array dw 2, 9, 6, 5, 8, 3, 7, 4, 1
n equ ($ - array)/2
.code
start: mov ax, @data
mov ds, ax
mov dx, offset array
mov cx, n
sort:
push cx

mov si, dx
mov di, offset array + 2
dec si
dec si
dec di
dec di
s:inc si
inc si
inc di
inc di
mov bx, [si]
cmp bx, [di]
jl s
xchg bx, [di]
mov [si], bx
loop s
pop cx
loop sort
mov dx, array
call arrout
mov ax, 4c00h
int 21h

arrout proc near ;参数为dx
push ax
push bx
push cx
push dx
mov si, dx
mov cx, n
disp:
mov bx, [si]
call output
inc si
inc si
loop disp
pop dx
pop cx
pop bx
pop ax
ret
arrout endp
output proc near ;参数为bx
push ax
push bx
push cx
push dx
mov ax, bx
mov bx, 10
mov cx, 0
insert:
cwd
div bx
push dx
inc cx
cmp ax, 0
jne insert
opt:pop dx
add dx, 30h
mov ah, 02h
int 21h
loop opt
pop dx
pop cx
pop bx
pop ax
ret
output endp
end start

不知道 为什么 这句loop 0015不仅没有执行,反而把很多寄存器都修改了,求大神解答,上面是我写的代码

;老实说,没看懂你的程序,这是我的冒泡程序,从大到小排列
dseg segment
a dw 90,27,102,37,56,33,54,223,33,24,93,12,65,78
dseg ends
cseg segment
assume cs:cseg, ds:dseg
start:
mov ax, dseg
mov ds, ax
mov cx, 14 ;简化了一下,直接送入n
dec cx
loop1:
mov di, cx
mov bx, 0
loop2:
mov ax, [bx]
cmp ax, [bx+2]
jge continue ;如果改为jl continue则为从小到大排列
xchg ax, [bx+2]
mov [bx],ax
continue:
add bx, 2
loop loop2
mov cx, di
loop loop1
mov ax,4c00h
int 21h
cseg ends
end start
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-01-18
冒泡法排序,程序并不很长。

楼主写了这老长的程序,用的是什么《法》?
相似回答
大家正在搜