~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 ;그