Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access with AI-Powered 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