Question: Write a complete program that includes a subroutine called GCD to compute the greatest common divisor ( GCD ) of two numbers a and b
Write a complete program that includes a subroutine called GCD to compute the greatest common divisor GCD of two numbers a and b
The subroutine will accept two inputs and return the result on the RTS Use the following algorithm to compute the GCDab
Algorithm : GCD Algorithm
Input : where
Output:
while do
while do
clarra
alarrc
end
while do
clarrb
blarrc
end
end
return
Include a main program to test your subroutine. Try testing with values store these using labels with the same name You can put
your test values in memory locations given by labels a b When the subroutine returns, your program should extract the result and store it at
the memory location given by label result. You may use the following template for your program.
;Implements a subroutine to compute GCD
orig
main
LD R stackbase
;set up RTS
; put your code for the mainline here
HALT
a fill ;change a and to test your program with different values
b fill
result blkw
stackbase fill ex
GCD
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
