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