Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago