Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions

Question

What are the common ways of estimating the capitalization rate?

Answered: 1 week ago

Question

Consistently develop management talent.

Answered: 1 week ago

Question

Create a refreshed and common vision and values across Europe.

Answered: 1 week ago

Question

Provide the best employee relations environment.

Answered: 1 week ago