Question
MIPSassembly language (Towers of Hanoi) Given three pegs and a stack of circular disks of various sizes on peg 1 with the largest on the
Given three pegs and a stack of circular disks of various sizes on peg 1 with the largest on the bottom, move the entire stack to peg 3 so that the disks are in the same order. Rules:
1. Only one disk may be moved at a time, and it must be the top disk on its peg.
2. No disk may be placed on top of a smaller disk.
Recursion works perfectly for this game. Suppose we look at the problem as follows: our task is to moveNdisks from peg 1 to peg 3. We win the game if we do the following:
1. Move (N-1) disks from peg 1 to peg 2.
2. Move the largest disk to peg 3.
3. Move (N-1) disks from peg 2 to peg 3.
Note:Complete this code
=========== code =======below=== MIPS assembly language====
.data
N: .word 5 # number of disks
.text
.globl main # needed by xspim
main: addi $a2, $zero, 1 # pass "1" for source in parameter 2
addi $a3, $zero, 2 # pass "2" for temp in parameter 3
addi $a1, $zero, 3 # pass "3" for dest in parameter 1
lw $t0, N # load the number of disks into $t0
la $s0, MOVES # load the starting address for the moves into $t1
add $a0, $zero, $t0 # pass the number of disks in parameter 0
jal hanoi # call procedure hanoi
j end
############################################################################################
hanoi: # Put your recursive function here!
############################################################################################
end: li $v0, 10 # syscall to exit cleanly
syscall
.data
MOVES: .word 0 # stores the moves
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started