~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 ;램 료