CSC231 Homework 10 2012

From dftwiki3
Revision as of 20:58, 14 November 2012 by Thiebaut (talk | contribs) (Requirements)
Jump to: navigation, search

--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 an output similar to the one shown above.
  • You may not pass the parameters via registers. Instead you must pass all four parameters through the stack.
  • Your program will also output at the end of the output the number of moves that were performed. You may not use a global variable to keep track of the count. If you are not sure how to do this in assembly, modify the python program to make it display the number of moves, then translate the python program in assembly.

Problem #2