⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hanoi.asm

📁 这是一个电话号码程序
💻 ASM
字号:
datarea segment
message1 db 'N=?',0ah,0dh,'$'
message2 db 'What is the name of spindle X ?'
	db 0ah,0dh,'$'
message3 db 'What is the name of spindle Y ?'
	db 0ah,0dh,'$'
message4 db 'What is the name of spindle Z ?'
	db 0ah,0dh,'$'
flag dw 0
constant dw 10000,1000,100,10,1
datarea ends

prognam segment
main proc far 
assume cs:prognam,ds:datarea
start:
	push ds
	sub ax,ax
	push ax
	mov ax,datarea
	mov ds,ax
	lea dx,message1
	mov ah,09h
	int 21h
	call decibin
	call crlf
	cmp bx,0
	jz exit
	lea dx,message2
	mov ah,09h
	int 21h
	mov ah,01h
	int 21h
	mov ah,0
	mov cx,ax
	call crlf
	lea dx,message3
	mov ah,09h
	int 21h
	mov ah,01h
	int 21h
	mov ah,0
	mov si,ax
	call crlf
	lea dx,message4
	mov ah,09h
	int 21h
	mov ah,01h
	int 21h
	mov ah,0
	mov di,ax
	call crlf
	call hanoi
exit:ret
main endp

hanoi proc near    ;define subprocedure
;Solves tower of HANOI puzzle
;Argement:(BX)=N,(CX)=X,(SI)=Y,(DI)=Z.
	cmp bx,1       ;if N=1,execute basis
	je basis       
	call save      ;save N,X,Y,Z
	dec bx
	xchg si,di
	call hanoi     ;call HANIO(N-1,X,Z,Y)
	call restor    ;restore N,X,Y,Z
	call print     ;print XNZ
	dec bx
	xchg cx,si
	call hanoi     ;call HANOI(N-1,Y,X,Z)
	jmp return
basis:call print   ;print X1Z
return:ret         ;return
hanoi endp         ;end subprocedure 

print proc near
	mov dx,cx
	mov ah,02h
	int 21h
	call binidec
	mov dx,di
	mov ah,02h
	int 21h
	call crlf
	ret 
print endp

save proc near
	pop bp
	push bx
	push cx
	push si
	push di
	push bp
	ret
save endp

restor proc near
	pop bp
	pop di
	pop si
	pop cx
	pop bx
	push bp
	ret
restor endp

decibin proc near
	mov bx,0
newchar:
	mov ah,1
	int 21h
	sub al,30h
	jl exit1
	cmp al,9d
	jg exit1
	cbw 
	xchg ax,bx
	mov cx,10d
	mul cx
	xchg ax,bx
	add bx,ax
	jmp newchar
exit1:ret
decibin endp

binidec proc near
	push bx
	push cx
	push si
	push di
	mov flag,0
	mov cx,5
	lea si,constant
dec_div:
	mov ax,bx
	mov dx,0
	div word ptr[si]
	mov bx,dx
	mov dl,al
	cmp flag,0
	jnz print1
	cmp dl,0
	je skip
	mov flag,1
print1:
	add dl,30h
	mov ah,02h
	int 21h
skip:
	add si,2
	loop dec_div
	pop di
	pop si
	pop cx
	pop bx
	ret
binidec endp

crlf proc near
	mov dl,0ah
	mov ah,02h
	int 21h
	mov dl,0dh
	mov ah,02h
	int 21h
	ret
crlf endp

prognam ends

	end start
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -