主题:[原创]帮忙看看这个递归的汉诺塔错在哪里了,
data segment
from db 41h
autx db 42h
to db 43h
n db 0
laber db '--->$'
ctrf db 0ah,0dh,'$'
data ends
code segment
main proc far
assume cs:code ,ds:data
start:
mov ax,data
mov ds,ax
mov ah,01h
int 21h ;输入数字
sub al,30h
mov n,al ;
lea dx,ctrf ;回车换行
mov ah, 9h
int 21h
call sort
mov ah,4ch
int 21h
main endp
;-------------------递归函数
sort proc near
push ax
push bx
push cx
push dx
mov al,from
mov bl,autx
mov cl,to
mov dl,n
cmp dl,1h
je print1
dec n
mov ch,to
xchg autx,ch
mov to,ch
call sort
print1:
add dl,30h
mov ah,2h
int 21h
mov dl,20h
mov ah,2h
int 21h
mov dl,al
mov ah,2h
int 21h
mov dx,offset laber
mov ah,9h
int 21h
mov dl,cl
mov ah,2h
int 21h
mov dl,20h
mov ah,2h
int 21h
cmp n,1h
je exit
mov ch,to
xchg from, ch
mov to,ch
call sort
exit: pop dx
pop cx
pop bx
pop ax
ret
sort endp
code ends
end start
请大家帮帮忙吧,我是新手,自己写的,帮忙改改吧,谢谢!
from db 41h
autx db 42h
to db 43h
n db 0
laber db '--->$'
ctrf db 0ah,0dh,'$'
data ends
code segment
main proc far
assume cs:code ,ds:data
start:
mov ax,data
mov ds,ax
mov ah,01h
int 21h ;输入数字
sub al,30h
mov n,al ;
lea dx,ctrf ;回车换行
mov ah, 9h
int 21h
call sort
mov ah,4ch
int 21h
main endp
;-------------------递归函数
sort proc near
push ax
push bx
push cx
push dx
mov al,from
mov bl,autx
mov cl,to
mov dl,n
cmp dl,1h
je print1
dec n
mov ch,to
xchg autx,ch
mov to,ch
call sort
print1:
add dl,30h
mov ah,2h
int 21h
mov dl,20h
mov ah,2h
int 21h
mov dl,al
mov ah,2h
int 21h
mov dx,offset laber
mov ah,9h
int 21h
mov dl,cl
mov ah,2h
int 21h
mov dl,20h
mov ah,2h
int 21h
cmp n,1h
je exit
mov ch,to
xchg from, ch
mov to,ch
call sort
exit: pop dx
pop cx
pop bx
pop ax
ret
sort endp
code ends
end start
请大家帮帮忙吧,我是新手,自己写的,帮忙改改吧,谢谢!