Question: ( 1 5 points ) The Euclidean Algorithm is used to find the Greatest Common Divisor ( GCD ) of two positive numbers; i .

(15 points) The Euclidean Algorithm is used to find the Greatest Common Divisor (GCD) of two positive numbers; i.e., GCD(10,15)=5, as 10=25 and 15=35, where 5 is a (and only in this case) common divisor between 10 and 10; and since 5 is the largest such divisor, it is the GCD.
Below are the steps of the algorithm for computing GCD:
(i) We put the larger number into R1 and the other number into R2.
(ii) Keep subtracting R2 from R1, until R1 contains a smaller value than R2 does.
(iii) From Step (ii), if R1 contains a positive number, we exchange values in R1 and R2, and repeat Step (ii).
(iv) From Step (ii), if R1 contains a zero, we stop the program. Whats in R2 is now the GCD.
Write an LC-3 assembly language program that implements the Euclidean Algorithm. [Hint: Might have additional steps in between; utilize CC for comparisons.]
Example: GCD(624,36)[i.e., R1=624 and R2=36]= GCD(588,36)= GCD(552,36)=...
= GCD(48,36)= GCD(12,36)= GCD(36,12)= GCD(24,12)= GCD(12,12)= GCD(0,12)=12.

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 Programming Questions!