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 a,b and return the result on the RTS. Use the following algorithm to compute the GCD(a,b).
Algorithm 1: GCD Algorithm
Input : a,b where a,b>0
Output: GCD(a,b)
1 while ab do
2 while a>b do
3,clarra-b
4,alarrc
5 end
6 while b>a do
7,clarrb-a
8,blarrc
9 end
10 end
11 return a
Include a main program to test your subroutine. Try testing with values a=66,b=12(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 3000
main
LD R6, stackbase
;set up RTS
; put your code for the mainline here
HALT
a . fill 66 ;change a and b to test your program with different values
b .fill 12
result .blkw 1
stackbase .fill ex 40
GCD
 Write a complete program that includes a subroutine called GCD to

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!