Difference between revisions of "CSC231 Final Exam 2014"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <onlydft> =Problem 1= * What is the decimal value represented by 1001011 in U(5,2)? (answer = 18.75) =Problem 2= * What is 10000001 in A(4,3) format? (answer -0.12...")
 
Line 12: Line 12:
 
* What is the real number (in decimal) with this binary representation: 1 1000 0000  
 
* What is the real number (in decimal) with this binary representation: 1 1000 0000  
 
(answer -2)
 
(answer -2)
 +
=Problem 4=
 +
<br />
 +
Write an assembly language program that solves the Tours of Hanoi problem.  If you have forgotten what this problem is about, read the [http://en.wikipedia.org/wiki/Tower_of_Hanoi Wikipedia page on the subject].  A Python version of the program is available [[CSC231_hanoi.py|here]].
 +
 +
Your program should use the 231Lib library to read an integer from the keyboard.  This number will represent the number of disks to move.  The three pegs are called A, B, and C, and the goal is to move ''N'' disk from A to B, using C as the temporary peg.
 +
 +
The output of the program should just be two uppercase letters per line, identifying the source and destination pegs for a move.
 +
 +
Here is an example of how your program should work:
 +
 +
<source lang="text">
 +
./hanoi
 +
2
 +
 +
2
 +
A C
 +
A B
 +
C B
 +
</source>
 +
The first 2 is the one entered by the user.  The program then prints a line-feed, then prints the number again, then another line feed.  In assembly this looks like this:
 +
<br />
 +
<source lang="asm">
 +
_start:
 +
                call    _getInput
 +
                call    _println
 +
                call    _printDec
 +
                call    _println
 +
</source>
 +
<br />
 +
You are free to implement your recursive moveDisk() function any way you wish.  In particular the passing of parameters is left up to you.  All that is important is the output of the moves, two letters per line, one space in between.
 +
<br />
 +
Submit your program to Moodle, in the Final Exam, Problem 4 section.
 +
 
</onlydft>
 
</onlydft>

Revision as of 21:10, 9 December 2014

--D. Thiebaut (talk) 15:02, 9 December 2014 (EST)



...