求救!!!实现一个数组的冒泡排序,在排序前后显示数组数据,数组第一个数据存储后面数据长度,DOS下输入,辅助作用。
现在有一个错误,估计不止,哪位大侠能帮忙看下,指出全部错误,直到实现理想功能。
data segment
list dw ?,20,21,22,23,24,25,26,27,28,29
data ends
code segment
main proc far
assume CS:code,DS:data
start:
push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
mov ah,01 ;input counting number,<=9
int 21h
sub al,30h ;转换为相应的二进制数
movzx dx,al ;ERROR! why
lea di,list
mov ds:[di],dx
call DispArray
call Sort
call DispArray
pop ax
pop ds
ret
main endp
Sort proc near
push di
push bx
push ax
mov cx,ds:[di]
dec cx
add di ,2
loop1: mov bx,cx
loop2: mov ax,ds:[di]
cmp ax,ds:[di+2]
jge continue
xchg ax,ds:[di+2]
mov [di],ax
continue:
add di,2
loop loop2
mov cx,bx
loop loop1
ret
Sort endp
DispArray proc near
push di
mov cx, ES:[di]
next: add di,2
mov bx,DS:[di]
; mov al,66 ;testing directive
; mov ah,2
; int 21h
call DISPBXD
loop next
pop di
ret
DispArray endp
DISPBXD PROC NEAR
push cx
push ax
push dx
push bx
MOV SI,10
XOR CX,CX
MOV AX,BX
next1: MOV DX,10
XOR DX,DX
DIV SI
PUSH DX
INC CX
CMP AX,0 ;商为0则完成转换
JNZ next1
OUTP: POP DX
ADD DL,30H
MOV AH,2h
INT 21H
LOOP OUTP
pop bx
pop dx
pop ax
pop cx
RET
DISPBXD ENDP
code ends
end start
------解决方案--------------------------------------------------------
应该是你逻辑不对,建议画流程图重整逻辑。
------解决方案--------------------------------------------------------
有点乱的说,,,
------解决方案--------------------------------------------------------
将movzx dx,al ;ERROR! why
lea di,list
mov ds:[di],dx这几行改成
CBW
lea di,list
mov ds:[di],AX
试试。。。。
------解决方案--------------------------------------------------------