Question
Background : The Tower of Hanoi is a mathematical game or puzzle. It consists of three rods and a number of disks of different sizes,
Background: The Tower of Hanoi is a mathematical game or puzzle. It consists of three rods and a number of disks of different sizes, which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 1. Only one disk can be moved at a time. 2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod. 3. No larger disk may be placed on top of a smaller disk. With 3 disks, the puzzle can be solved in 7 moves. The minimal number of moves required to solve a Tower of Hanoi puzzle is 2 1, where is the number of disks.
Assignment: There are several different ways to implement a solution, but one of the simplest uses a recursive approach. Convert the recursive C function given below into an *****assembly language source code file*****(Please type it correctly in assembly). Function Move1Disk is provided in the main program.
void Hanoi(int num, int fm, int to, int aux) ; { if (num > 1) Hanoi(num - 1, fm, aux, to) ;
Move1Disk(fm, to) ;
if (num > 1) Hanoi(num - 1, aux, to, fm) ; }
/*****************For your Reference********************************/
//Here is Move1Disk code for your reference
#include
#include
#include
#include "library.h"
#include "graphics.h"
#define FONT_MOVE Font12
#define DISK_MSEC 20
static BOOL step = FALSE ;
void Move1Disk(int fm, int to)
{
int diam ;
if (fm < 0 || fm > 2) Error("Move1Disk", "fm < 0 or > 2") ;
if (to < 0 || to > 2) Error("Move1Disk", "to < 0 or > 2") ;
DisplayMessage(&FONT_MOVE, "Move from %d to %d", fm + 1, to + 1) ;
if (PushButtonPressed()) step = TRUE ;
if (step) WaitForPushButton() ;
else Delay(DISK_MSEC) ;
diam = Sub(fm) ;
Add(to, diam) ;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started