Question: Problems Problem 5 (Euclid's Algorithm, Recursive Approach) Write an HMMM program ged.rec.hamm that takes two nonnegative integers r and y as input and prints their

 Problems Problem 5 (Euclid's Algorithm, Recursive Approach) Write an HMMM program

Problems Problem 5 (Euclid's Algorithm, Recursive Approach) Write an HMMM program ged.rec.hamm that takes two nonnegative integers r and y as input and prints their greatest common divisor (gcd), calculated recursively using Euclid's Algorithm: gcd(y, x mod y) if y 0, and gcd(x,y) = Hints Set r15 (stack pointer) to 100; read the inputs z and y into registers ri and 12 respectively: call the function f(x, y) that calculates the desired result in register r3; write the result; halt. In the function f(x, y), calculate gcd(z, y) in register r3; return to the caller. CA) is r2 equal to 0? yes: # base case r3 r1 Juap to caller incresent r15 by 1 ao : store r14 (retura address) in senory at r15 r1 r2 and r2 r1 mod r2 (t) recursive function call to CA) load value in sesory at r15 into ri4 decrement r16 by 1 Jump to caller r2+ r4 mod r2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!