U E D R , A S I H C RSS

Hanoi Problem/영동

  • ... 블리 나게 나는 군...
  • 그리고 push를 면 각 변 pop 다고 는데, 그게 나라 push 반대 로 pop 는 것더군.

~cpp 
; 
.model small
.stack 100h

.data
message1 db "have move ", '$'
message2 db "th disk from ", '$'
message3 db "to ", '$'
n dw 5			;disk
from dw 1		; 기둥(1)
by dw 2			; 기둥(2)
to dw 3			;목 기둥(3)	

.code
extrn Crlf:proc
extrn Writeint:proc

main proc
	mov ax, @data
	mov ds, ax
	mov bx, 10	;Writeint 10 력

	call Move	;Move 
			;Move(from, to, by)
	mov ax, 4C00h	;료
	int 21h
main endp

Move proc		;Move (되는 부)
	cmp n, 0	;n=0면
	jz endmove	;Move 로 감
	
	push n		;n값  
	dec n		;n-1

	push from	;from  
	push by		;by를  
	push to		;to를  
	
	mov ax, by	;by to 를 바꿔.(ax를 temp로 )
	mov si, to	;메모리   되므로
	mov by, si	;si를 
	mov to, ax

	call Move	;Move(n-1, from, by, to)
			;(by to 를 바꿔  )
	pop to		;다 to, by, from, n 대로 꺼
	pop by		;므로 빼는   다
	pop from		
	pop n
	
	mov ah, 9	;message1 력
	mov dx, offset message1
	int 21h
	
	mov ax, n	;몇기는 력
	call Writeint
	
	mov dx, offset message2
	mov ah, 9	;message2를 력
	int 21h

	mov ax, from	;기는  력
	call Writeint
	call Space	; 고

	mov dx, offset message3
	mov ah, 9	;message3 력
	int 21h

	mov ax, to	;목 력
	call Writeint

	call Crlf	;

	push n		;n  고
	dec n		;n-1

	push from	;from, by, to를 례로  
	push by
	push to

	mov ax, from	;from과 by를 바(ax를 temp로 )
	mov si, by	;메모리    므로
	mov from, si	;si를 
	mov by, ax
	
	call Move	;Move(by, to, from)  
	
	pop to		;to, by, from, n 뺌
	pop by
	pop from	
	pop n

	endmove:	
	ret		; 끝
Move endp

Space proc		;
	mov dl, " "
	mov ah, 2
	int 21h		; 력
	ret
Space endp

end main		;로그램 
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:21
Processing time 0.0083 sec