CSC231 Homework 10 2012

From dftwiki3
Revision as of 20:51, 14 November 2012 by Thiebaut (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 the same output as shown above.
  • You can pass the parameters using registers for full credits, but you get 1/3 extra credits if you pass all four parameters through the stack.