Solved Problems on Computer Architecture - Assignment 4 | CPSC 321, Lab Reports of Computer Science

Material Type: Lab; Subject: COMPUTER SCIENCE; University: Texas A&M University; Term: Unknown 1989;

Typology: Lab Reports

Pre 2010

Uploaded on 02/13/2009

koofers-user-vl1
koofers-user-vl1 🇺🇸

3.7

(3)

9 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPSC 321:501-503 - Computer Architecture
Texas A&M University
Department of Computer Science
Fall 2006
Lab 4 (100 pts) – Towers of Hanoi
Complete by yourself
Release date: 25 September 2006
Due date: One week after the lab
1. Towers of Hanoi problem
Facts (from www.lawrencehallofscience.org):
The Tower of Hanoi (sometimes referred to as the Tower of Brahma or the End of the World Puzzle)
was invented by the French mathematician, Edouard Lucas, in 1883. He was inspired by a legend that
tells of a Hindu temple where the pyramid puzzle might have been used for the mental discipline of
young priests. Legend says that at the beginning of time the priests in the temple were given a stack of
64 gold disks, each one a little smaller than the one beneath it. Their assignment was to transfer the 64
disks from one of the three poles to another, with one important provision; a large disk could never be
placed on top of a smaller one. The priests worked very efficiently, day and night. When they finished
their work, the myth said, the temple would crumble into dust and the world would vanish.
The objective of this assignment is to write a MIPS assembly program to solve the Towers of Hanoi
problem and to demonstrate the steps from the initial to the final configuration. Accept as input, the
number of disks (N) to be moved (Assume the number will be <=32).
Problem formulation
There are N disks labeled 1..N, with the larger label indicating a larger disk. These disks can be stacked
on poles A, B and C. Initially all disks form a tower on pole A, as shown.
1 1
2 2
. .
. .
. .
N N
----- ----- ----- ----- ----- -----
A B C A B C
Initial state Final state
The problem is to move the tower from A to C with the help of tower B, according to the following
rules:
Page
1
of
3
CPSC 321
Lab 4
9/1/2006
file://H:\web_courses\cpsc321\labs\lab4_06c.html
pf3

Partial preview of the text

Download Solved Problems on Computer Architecture - Assignment 4 | CPSC 321 and more Lab Reports Computer Science in PDF only on Docsity!

CPSC 321:501-503 - Computer Architecture

Texas A&M University

Department of Computer Science

Fall 2006

Lab 4 (100 pts) – Towers of Hanoi

Complete by yourself

Release date: 25 September 2006 Due date: One week after the lab

1. Towers of Hanoi problem

Facts ( from www.lawrencehallofscience.org ):

The Tower of Hanoi (sometimes referred to as the Tower of Brahma or the End of the World Puzzle) was invented by the French mathematician, Edouard Lucas, in 1883. He was inspired by a legend that tells of a Hindu temple where the pyramid puzzle might have been used for the mental discipline of young priests. Legend says that at the beginning of time the priests in the temple were given a stack of 64 gold disks, each one a little smaller than the one beneath it. Their assignment was to transfer the 64 disks from one of the three poles to another, with one important provision; a large disk could never be placed on top of a smaller one. The priests worked very efficiently, day and night. When they finished their work, the myth said, the temple would crumble into dust and the world would vanish.

The objective of this assignment is to write a MIPS assembly program to solve the Towers of Hanoi problem and to demonstrate the steps from the initial to the final configuration. Accept as input, the number of disks (N) to be moved ( Assume the number will be <=32 ).

Problem formulation

There are N disks labeled 1..N, with the larger label indicating a larger disk. These disks can be stacked on poles A, B and C. Initially all disks form a tower on pole A, as shown.

1 1 2 2

.. .. .. N N


A B C A B C Initial state Final state

The problem is to move the tower from A to C with the help of tower B, according to the following rules:

(a) Only one disk can be moved at a time; (b) No disk can rest on a smaller disk.

If we write hanoi(N,source,desk,aux)^ to denote “pass N disks from pole source^ to pole dest (^) using pole aux”, then the problem is:

hanoi(N, A, C, B)

Rule (b) implies that for disk N (the largest disk) to be moved to C, the N-1 smaller disks on top of it must first be placed on B, so that disk N can then pass from A to C. To finish the solution then requires passing the N-1 disks from B to C. This implies a recursive strategy that can be written as follows:

hanoi ( N, source, dest, aux ) { if N > 0 then hanoi(N - 1, source, aux, dest) hanoi(N - 1, aux, dest, source) end if }

Along with solving the problem, you need to illustrate the state of the three towers after every disk move. So for N=3, you would start by showing the initial configuration of the towers, and then each step:

A B C

A B C

A B C