Homework

Homework Questions? Ask a Tutor for Answers ASAP

Connect one-on-one with {0} who will answer your question

The greatest common divisor (GCD)...

The greatest common divisor (GCD) of two integers is the largest positive integer that divides both evenly. Thus GCD(100, 240) is 20, GCD(34, 27) is 1 and GCD(0, 14) is 14. A standard elementary programming exercise computes the GCD of M and N (both > 0) without using division (which is slow) by the following method:

while (MN) do

if (N > M) then N = N – M else M = M – N;

GCD = N;

It is easy to see that this method works. Since M and N start out nonzero, they remain nonzero, and every time thru the loop the larger gets smaller. Therefore the loop either terminates or they both reach 1, in which case the loop terminates. It should be easy to see that the GCD of M and N after the loop is the same as before the loop, and that GCD(N,N)=N;

Write a separately assembled function GCD to compute the GCD of the integers in AX and BX using the algorithm and return the value in AX. Treat the cases M or N = 0 or negative as special cases. (GCD(-M,N) = GCD(M,N); GCD(-32768,-32768)= -32768, GCD(-32768,N) = GCD(16384,N) if N -32768. GCD(0,0) should be infinity, but return 0.) Be sure to test your procedure as completely as possible.

You will need to write two programs. The first is the GCD procedure in a separate file and the second will be the program that tests the GCD procedure. Your test program must loop and allow the user to run the GCD procedure on two inputs. You will stop the program by asking the user if they want to continue and checking their response to an input of Y/N.

Be sure to document your code and use procedures when ever possible in this program. Remember that the main procedure answers the question “What does the program do?” and the procedures tell how the task is performed.

while (MN) do

if (N > M) then N = N – M else M = M – N;

GCD = N;

It is easy to see that this method works. Since M and N start out nonzero, they remain nonzero, and every time thru the loop the larger gets smaller. Therefore the loop either terminates or they both reach 1, in which case the loop terminates. It should be easy to see that the GCD of M and N after the loop is the same as before the loop, and that GCD(N,N)=N;

Write a separately assembled function GCD to compute the GCD of the integers in AX and BX using the algorithm and return the value in AX. Treat the cases M or N = 0 or negative as special cases. (GCD(-M,N) = GCD(M,N); GCD(-32768,-32768)= -32768, GCD(-32768,N) = GCD(16384,N) if N -32768. GCD(0,0) should be infinity, but return 0.) Be sure to test your procedure as completely as possible.

You will need to write two programs. The first is the GCD procedure in a separate file and the second will be the program that tests the GCD procedure. Your test program must loop and allow the user to run the GCD procedure on two inputs. You will stop the program by asking the user if they want to continue and checking their response to an input of Y/N.

Be sure to document your code and use procedures when ever possible in this program. Remember that the main procedure answers the question “What does the program do?” and the procedures tell how the task is performed.

Show More

Show Less

Was this answer helpful?

Describe your issueThe assistant will guide you

Chat 1:1 with a tutorLicensed Experts are available 24/7

100% satisfaction guaranteeGet all the answers you need

Related Homework Questions

I have a problem and I need help to solve it step by step

I have a problem and I need help to solve it step by step for micorprocessor assembly languageTutor's Assistant: I'll do all I can to help. Can you tell me more about what's going on?I can send you th… read more

Develop an x86 assembly language program that properly

Second Opinion] Develop an x86 assembly language program that properly executes an "is even" function: bool isEven(int value) If the value passed in is even, return 1 If the value passed in is odd, re… read more

Java question. can you rewrite the following code and

java question. can you rewrite the following code and implement the operations interfaceA rational number is ***** number that can be expressed as the quotient or fraction of two integer values, with … read more

Def divisors(n): """computes and returns a list of positive

Second opinion] def divisors(n): """computes and returns a list of positive integer divisors of a given integer""" div=[1] for i in range (2, n//2+1): #largest posible divisor is equal to half of the … read more

I have a lab due today and I'm not sure how to start it. I

I have a lab due today and I'm not sure how to start it. I would like help with making the pseudo code if possible. … read more

Write a function named "reduce" that takes two positive

Write a function named "reduce" that takes two positive integer arguments, call them "num" and "denom", treats them as the numerator and denominator of a fraction, and reduces the fraction. … read more

For LogicPro only.... Java homework program. Jagged Array

For LogicPro only.... Java homework program.Jagged Array Your task for this problem is to read in a jagged array of integers from user input. First ask for the number of rows. Then ask for each row as… read more

Write a program that prompts a user for two integers and

Write a program that prompts a user for two integers and passes them to a function that passes back the greatest common divisor and the least common multiplier. The calculation of the greatest common … read more

1. Write a recursive algorithm to compute a+b, where a and

1. Write a recursive algorithm to compute a+b, where a and b are nonnegative integers. 2. Let a be an array of integers. Write a recursive algorithm to compute the average of the elements of the array… read more

The following instructions must be adhered to. Variance from

The following instructions must be adhered to. Variance from these instructions will result in a penalty of 50% of the assignment: 1. The use of any of the following C statements or functions is not p… read more

Today in class I was asked to do the following: Write a class

Today in class I was asked to do the following: Write a class Automaton which implements a basic vending machine. The machine has three things to o er: water, cola, and juice. The prices are 10, 12, a… read more

In this assignment you will write a Java program that prompts

In this assignment you will write a Java program that prompts the user for a string, extracts the integers from it, then displays the list of integers one line at a time. It's very similar to an earli… read more

In this assignment you will write a Java program that prompts

In this assignment you will write a Java program that prompts the user for a string, extracts the integers from it, then displays the list of integers one line at a time. It's very similar to an earli… read more

To RRJha Next project: Sum-Over-a-Range Program It

To RRJha Next project: Sum-Over-a-Range Program It is desired to create a program that calculates the sum of integers in a given range that are also evenly divisible by a given integer. (ex. determine… read more

For problems 1-3 you must: Write a Python (.py) program Test,

For problems 1-3 you must: Write a Python (.py) program Test, debug, and execute the Python program Submit a copy of your commented source code on-line (10 pts.) Using a for loop, write a program that… read more

I am doing this in JAVA not javascript:Objective: In this

I am doing this in JAVA not javascript: Objective: In this project, you will utilize file input/output operation, if/else statement, for/while loop, break, continue, switch, and methods. 1. Create a J… read more

1.) use top down modular approach and pseudocode to design

1.) use top down modular approach and pseudocode to design a suitable program to solve it. The number N factorial, denoted ny N!, is defined to be the product of the first N positive integers: N! = 1*… read more

Please C programming only... Write a C program that accepts

Please C programming only... Write a C program that accepts a month and day (for example, June 14) from the keyboard as input. Store this information in one string called date. Call a function named s… read more

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.

JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.

Web sites like justanswer.com/legal

...leave nothing to chance.

...leave nothing to chance.

Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.

Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.

I will tell you that...the things you have to go through to be an Expert are quite rigorous.

Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help.

Freshfield, Liverpool, UK

This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!!

Los Angeles, CA

Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult.

Hesperia, CA

I couldn't be more satisfied! This is the site I will always come to when I need a second opinion.

Kernersville, NC

Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around.

Woodstock, NY

Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know.

Elkton, Maryland

He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here.

Dallas, TX

< Previous | Next >

Scott

MIT Graduate

5,558 satisfied customers

MIT Graduate (Math, Programming, Science, and Music)

LogicPro

Engineer

18,409 satisfied customers

Expert in Python,Java C++ C C# VB Javascript Design SQL HTML

Manal Elkhoshkhany

Tutor

4,775 satisfied customers

More than 5000 online tutoring sessions.

Linda_us

Finance, Accounts & Homework Tutor

3,138 satisfied customers

Post Graduate Diploma in Management (MBA)

Chris M.

M.S.W. Social Work

2,852 satisfied customers

Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)

F. Naz

Chartered Accountant

2,273 satisfied customers

Experience with chartered accountancy

Bizhelp

CPA

1,887 satisfied customers

Bachelors Degree and CPA with Accounting work experience

< Previous | Next >

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.