Difference between revisions of "CSC231 Homework 10 2012"
(Created page with "--~~~~ ---- <bluebox> This assignment is due on 11/28/12 evening, at midnight. </bluebox> =Problem 1= Implement a recursive version of the Towers of Hanoi in assembly. You can...") |
(→Problem 1) |
||
Line 74: | Line 74: | ||
==Requirements== | ==Requirements== | ||
* Your program will call the recursive function moveDisk and pass it the characters 'A', 'B', 'C' and the number 5, and will display the same output as shown above. | * Your program will call the recursive function moveDisk and pass it the characters 'A', 'B', 'C' and the number 5, and will display the same output as shown above. | ||
− | * You | + | * You may not pass the parameters via registers. Instead you must pass all four parameters through the stack. |
Revision as of 20:52, 14 November 2012
--D. Thiebaut 20:51, 14 November 2012 (EST)
This assignment is due on 11/28/12 evening, at midnight.
Problem 1
Implement a recursive version of the Towers of Hanoi in assembly.
You can use this Python version for inspiration:
# hanoi.py (Python V 2.7)
# D. Thiebaut
# implements the game of hanoi in python.
# uses recursion.
#
# to run, type
# python hanoi.py
# at the command line
def moveDisk( source, dest, extra, n ):
if n==1:
print "move disk from %s to %s" % ( source, dest )
return
# more than 1 disk...
moveDisk( source, extra, dest, n-1)
print "move disk from %s to %s" % ( source, dest )
moveDisk( extra, dest, source, n-1)
def main():
moveDisk( "A", "B", "C", 5 )
main()
The output of the program is shown below:
move disk from A to B
move disk from A to C
move disk from B to C
move disk from A to B
move disk from C to A
move disk from C to B
move disk from A to B
move disk from A to C
move disk from B to C
move disk from B to A
move disk from C to A
move disk from B to C
move disk from A to B
move disk from A to C
move disk from B to C
move disk from A to B
move disk from C to A
move disk from C to B
move disk from A to B
move disk from C to A
move disk from B to C
move disk from B to A
move disk from C to A
move disk from C to B
move disk from A to B
move disk from A to C
move disk from B to C
move disk from A to B
move disk from C to A
move disk from C to B
move disk from A to B
Requirements
- Your program will call the recursive function moveDisk and pass it the characters 'A', 'B', 'C' and the number 5, and will display the same output as shown above.
- You may not pass the parameters via registers. Instead you must pass all four parameters through the stack.