Question: Assembler : Borland TASM 3 . 0 File Name : project 2 . asm Input : Number of disks, starting pole, ending pole Output :
Assembler : Borland TASM
File Name : projectasm
Input : Number of disks, starting pole, ending pole
Output : Sequence of moves to solve the Towers of Hanoi
Input Files : None
Output Files: None
PROCEDURES CALLED:
External procedures called:
FROM iofar.lib: PutStr, PutCrLf, GetDec, PutDec
Internal procedures called:
Greet, Hanoi, InputDisks
INCLUDELIB iofar
; BEGIN MAIN PROGRAM
DOSSEG
model large
stack h ; Increase stack size for recursive calls
; MAIN PROGRAM DATA SEGMENT
; Define data segment
data
NumDisks dw
StartPole dw
EndPole dw
Prompt db 'Enter the number of disks : $
Prompt db 'Enter the starting pole : $
Prompt db 'Enter the ending pole : $
InvalidMsg db 'Invalid input! Starting and ending poles must be different.$
MoveMsg db 'Move disk $
FromMsg db from pole $
ToMsg db to pole $
; Define code segment
code
ProgramStart PROC
; Initialize data segment
mov ax @data
mov ds ax
; Call Greet procedure
call Greet
; Input number of disks
call InputDisks
; Call the Hanoi procedure with the input parameters
push NumDisks
push StartPole
push EndPole
call Hanoi
; Exit to the operating system
mov axch
int h
ProgamStart ENDP
; Procedure to input number of disks and poles
InputDisks PROC
InputDisksStart:
; Input number of disks
mov dx OFFSET Prompt
mov ahh
int h
call GetDec
mov NumDisks, ax
cmp ax
jl InvalidInput
cmp ax
jg InvalidInput
; Input starting pole
mov dx OFFSET Prompt
mov ahh
int h
call GetDec
mov StartPole, ax
cmp ax
jl InvalidInput
cmp ax
jg InvalidInput
; Input ending pole
mov dx OFFSET Prompt
mov ahh
int h
call GetDec
mov EndPole, ax
cmp ax
jl InvalidInput
cmp ax
jg InvalidInput
cmp ax StartPole
je InvalidInput
ret
InvalidInput:
mov dx OFFSET InvalidMsg
mov ahh
int h
jmp InputDisks
InputDisks ENDP
; Procedure to solve Towers of Hanoi recursively
Hanoi PROC
; Save registers on the stack
pusha
pushf
; Set up bp register to point to parameters
mov bp sp
; If NumDisks is print the move
mov axbp ; NumDisks
cmp ax
jne RecursiveCall
; Print the move
mov dx OFFSET MoveMsg
mov ahh
int h
mov axbp ; NumDisks
call PutDec
mov dx OFFSET FromMsg
mov ahh
int h
mov axbp ; StartPole
call PutDec
mov dx OFFSET ToMsg
mov ahh
int h
mov axbp ; EndPole
call PutDec
call PutCrLf
jmp EndHanoi
RecursiveCall:
; Recursive call: HanoiNumDisks StartPole, StartPole EndPole
mov axbp ; NumDisks
dec ax ; NumDisks
push ax
mov axbp ; StartPole
push ax
mov ax
sub axbp ; StartPole
sub axbp ; EndPole
push ax
call Hanoi
; Print the move
mov dx OFFSET MoveMsg
mov ahh
int h
mov axbp ; NumDisks
call PutDec
mov dx OFFSET FromMsg
mov ahh
int h
mov axbp ; StartPole
call PutDec
mov dx OFFSET ToMsg
mov ahh
int h
mov axbp ; EndPole
call PutDec
call PutCrLf
; Recursive call: HanoiNumDisks StartPole EndPole, EndPole
mov axbp ; NumDisks
dec ax ; NumDisks
push ax
mov ax
sub axbp ; StartPole
sub axbp ; EndPole
push ax
mov axbp ; EndPole
push ax
call Hanoi
EndHanoi:
; Restore registers from stack
popf
popa
; Return to caller module
ret ; Clean up the stack by removing the parameters
Hanoi ENDP
comment
PROCEDURE HEADER
PROCEDURE NAME : Greet
PURPOSE : To print initial greeting messages to the user
INPUT PARAMETERS : None
OUTPUT PARAMETERS or RETURN VALUE: None
NONLOCAL VARIABLES REFERENCED: None
NONLOCAL VARIABLES MODIFIED :None
PROCEDURES CALLED :
FROM iofar.lib: PutCrLf
CALLED FROM : Main Program
; SUBROUTINE DATA SEGMENT
data
Msg db 'Program: Towers of Hanoi $
Msg db 'Programmer: $
Msg db 'Date: $
; SUBROUTINE CODE SEGMENT
code
Greet PROC NEAR
mov ax @data
pusha
pushf
mov dx OFFSET Msg
mov ah
int h
call PutCrLf
mov dx OFFSET Msg
mov ah
int h
call PutCrLf
mov dx OFFSET Msg
mov ah
int h
call PutCrLf
popf
popa
ret
Greet ENDP
end ProgramStart
This code is not working.Please correct this code and solve for tower of hanoi. Please provide full code not partial. Also provide all PROCEDURE
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
