Write the recursive MIPS code (with abundant explanatory comments) for the Tower of Hanoi problem of transferring a stack of N disks (smaller sized disks stacked over the larger sized ones) from a source peg to a destination peg via a third (temporary rest peg) under the constraints:
1. Only one disk is moved at a time from one peg to another
2. At no time, a larger disk will sit on a smaller one.
li $v0, 4
la $s0, Prompt #Enter number of
disk N in s0
syscall
li $v0, 5
syscall
add $s0, $v0, $zero
addi $p1, $zero, 1
#$p1 = start
peg
addi $p2, $zero, 3
#$p2 = end
peg
addi $p3, $zero, 2
#$p3 = extra
peg
jal hanoi_towers
hanoi_towers: #Equivalent C implementation for
reference
# if (num_of_disks == 1)
# move disk to end_peg
# else
# hanoi_towers(num_of_disks-1, start_peg, extra_peg, end_peg)
# move disk from start_peg to end_peg
# hanoi_towers(num_of_disks-1, extra_peg, end_peg,
start_peg)
# if (num_of_disks == 1)
addi $t0, $s0, 0
addi $t1, $zero, 1
bne $s0, $t1, else
li $v0, 4
la $s0, Move
syscall
li $v0, 1
move $s0, $p1
syscall
li $v0, 4
la $s0, To
syscall
li $v0, 1
move $s0, $p2
syscall
addi $s0, $t0, 0
jr $ra
else:
addi $sp, $sp, -20
sw $ra, 16($sp)
sw $p3, 12($sp)
sw $p2,
8($sp)
#store p2(end_peg)
sw $p1,
4($sp)
#store p1(start_peg)
sw $s0,
0($sp)
#store s0(num_of_disks)
#recursive call to function hanoi_towers
addi $t3, $p3, 0
addi $p3, $p2,
0
#extra_peg = end_peg
addi $p2, $t3,
0
#end_peg = extra_peg
addi $s0, $s0,
-1
#reduce no of disks by 1
jal hanoi_towers
lw $ra, 16($sp)
lw $p3, 12($sp)
lw $p2, 8($sp)
lw $p1, 4($sp)
lw $s0, 0($sp)
#move a disk from start_peg to end_peg
addi $t0, $s0, 0
addi $t1, $zero, 1
li $v0, 4
la $s0, Move
syscall
li $v0, 1
move $s0, $p1
syscall
li $v0, 4 la $s0, To
syscall
li $v0, 1
move $s0, $p2
syscall
addi $s0, $t0, 0
#hanoi_towers(num_of_disks-1, extra_peg, end_peg,
start_peg)
addi $t3, $p3, 0
addi $p3, $p1, 0
addi $p1, $t3, 0
addi $s0, $s0,
-1
#num of disk--
jal hanoi_towers
lw $ra, 16($sp)
addi $sp, $sp, 20
#return
add $v0, $zero, $t5
jr $ra
Write the recursive MIPS code (with abundant explanatory comments) for the Tower of Hanoi problem of...
Describe a recursive algorithm for solving the Towers of Hanoi puzzle for an arbitrary n (see Creativity Exercise C-5.16 for more details). C-5.16 In the Towers of Hanoi puzzle, we are given a platform with three pegs, a, b, and c, sticking out of it. On peg a is a stack of n disks, each larger than the next, so that the smallest is on the top and the largest is on the bottom. The puzzle is to move all...
Write MIPS code (with abundant explanatory comments) for recursive summation of N-numbers using the formal procedure of putting all arguments and other necessary variables on stack and getting them back before exit from the stack.
Write MIPS code (with abundant explanatory comments) for recursive summation of N-numbers using the formal procedure of putting all arguments and other necessary variables on stack and getting them back before exit from the stack.
write in c programming language . question 5.36 Fibonaco for its rets ing terms, a) Write a warruse function fibonacci(n) that calculatus 0, 1, 1, 2, 3, 5, 8, 13, 21,... (n) that calculates the n" Fib begins with the terms and 1 and has the property preceding terms. a) Write a cand unsigned long long int for i number. Use unsigned int for the function's paramete her that can be printed on your system. type. b) Determine the largest...
Please write a recursive Java program to solve the Tower of Hanoi game for n disks on pole A. Please read the textbook page 176 – 180 to fully understand this game or puzzle. The game consists of n disks and three poles: A (the source), B (the destination), and C (the spare). Initially, all the disks are on pole A. The game is to move all disks (one by one) from pole A to pole B using pole C...
In the classic problem of the Towers of Hanoi, you have 3 rods and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (e.g., each disk sits on top of an even larger one).You have the following constraints: (A) Only one disk can be moved at a time. (B) A disk is slid off the top of one rod onto the next rod....
Part A [50] in c++ A toy that many children play with is a base with three pegs and five disks of different diameters. The disks begin on one peg, with the largest disk on the bottom and the other four disks added on in order of size. The idea is to move the disks from the peg they are on to another peg by moving only one disk at a time and without ever putting a larger disk on...
Write a function in prolog pragramming languaged named, "ionah", that takes a single number as input and prints out the solution to the inverted disk problem for that many disks. This is the problem of moving a stack of k disks of increasing size from bottom to top, from the first peg to the third peg with another peg that may be used as well, subject to the condition that a smaller disk is never put on top of a larger...
Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic memory allocation, pointers, recursion, and debugging Mandatory Instructions Develop a C++ object oriented solution to the Towers of Hanoi puzzle. Your solution will involve designing two classes one to represent individual Disk and another to represent the TowersOfHanoi game. TowersOfHanoi class will implement the game with three linked lists representing disks on each...