Question

In Assembly Language Please display results and write assembler code in (gcd.s) The Euclidean algorithm is...

In Assembly Language

Please display results and write assembler code in (gcd.s)

The Euclidean algorithm is a way to find the greatest common divisor of two positive integers, a and b. First let me show the computations for a=210 and b=45.

Divide 210 by 45, and get the result 4 with remainder 30, so 210=4·45+30.

Divide 45 by 30, and get the result 1 with remainder 15, so 45=1·30+15.

Divide 30 by 15, and get the result 2 with remainder 0, so 30=2·15+0.

The greatest common divisor of 210 and 45 is 15.

Formal description of the Euclidean algorithm

Input Two positive integers, a and b.

Output The greatest common divisor, g, of a and b.

Internal computation

1. If a<b, exchange a and b.

2. Divide a by b and get the remainder, r. If r=0, report b as the GCD of a and b.

3. Replace a by b and replace b by r. Return to the previous step.

Your assignment is to write an assembler code (gcd.s) that asks the user two positive numbers and calculates their greatest common denominator.

For example, you program should produce the following outputs:

Enter first positive integer: 6

Enter second positive integer: 8

The GCD is 2

0 0
Add a comment Improve this question Transcribed image text
Answer #1
DATA SEGMENT
  NUM1 DW 6
  NUM2 DW 8
  GCD DW ?
DATA ENDS
CODE SEGMENT
  ASSUME CS:CODE,DS:DATA
  START: MOV AX,DATA   ;Load the Data to AX.
         MOV DS,AX     ;Move the Data AX to DS.
         MOV AX,NUM1   ;Move the first number to AX.
         MOV BX,NUM2   ;Move the second number to BX.
  UP: CMP AX,BX        ;Compare the two numbers.
      JE EXIT          ;If equal, go to EXIT label.
      JB EXCG          ;If first number is below than second,
                       ;go to EXCG label.
  UP1: MOV DX,0H       ;Initialize the DX.
       DIV BX          ;Divide the first number by second number.
       CMP DX,0        ;Compare remainder is zero or not.
       JE EXIT         ;If zero, jump to EXIT label.
       MOV AX,DX       ;If non-zero, move remainder to AX.
       JMP UP          ;Jump to UP label.
  EXCG:XCHG AX,BX     ;Exchange the remainder and quotient.
       JMP UP1        ;Jump to UP1.
  EXIT:MOV GCD,BX     ;Store the result in GCD.
       MOV AH,4CH
       INT 21H
  CODE ENDS
  END START
Add a comment
Know the answer?
Add Answer to:
In Assembly Language Please display results and write assembler code in (gcd.s) The Euclidean algorithm is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a Find the greatest common divisor (gcd) of 322 and 196 by using the Euclidean Algorithm....

    a Find the greatest common divisor (gcd) of 322 and 196 by using the Euclidean Algorithm. gcd- By working back in the Euclidean Algorithm, express the gcd in the form 322m196n where m and n are integers b) c) Decide which of the following equations have integer solutions. (i) 322z +196y 42 ii) 322z +196y-57

  • Use R language to program Problem 1: Greatest Common Divisor (GCD) Please write two functions, g...

    Use R language to program Problem 1: Greatest Common Divisor (GCD) Please write two functions, g edi ) and gcdr , which both take two integers a, b and calculates their greatest common divisor (GCD) using the Euclidean algorithm gcdi () should do so using iteration while gcdr () should use recursion. Then write a third function, gcd(), which takes two integers a, band an optional third argument nethod which takes a charater string containing either "iterative" or "recursive", with...

  • 1. (10 points) GCD Algorithm The greatest common divisor of two integers a and b where...

    1. (10 points) GCD Algorithm The greatest common divisor of two integers a and b where a 2 b is equal to the greatest common divisor of b and (a mod b). Write a program that implements this algorithm to find the GCD of two integers. Assume that both integers are positive. Follow this algorithm: 1. Call the two integers large and small. 2. If small is equal to 0: stop: large is the GCD. 3. Else, divide large by...

  • C++ PROGRAM ONLY! For this lab you need to write a program that will read in...

    C++ PROGRAM ONLY! For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using a recursive implementation of the Euclidean algorithm) to a file. In Lab #3, you implemented this program using an iterative method. Greatest Common Divisor In mathematics, the greatest common divisor (GCD) of two or more integers (when at least one of of them is zero then the larger value is the GCD....

  • Cryptography Computer Security Greatest Common Divisor Assignment Instructions In software, implement the Euclidean algorithm to find...

    Cryptography Computer Security Greatest Common Divisor Assignment Instructions In software, implement the Euclidean algorithm to find the greatest common divisor of any two positive integers. It should implement the pseudocode provided in the text. It should allow the user to enter two integers.   Your program should output the intermediate values of q, r1, r2 for each step and should return the greatest common divisor. Challenge component: Allow the user's input to be zero as well as the positive integers. Provide...

  • C++ I do not understand this problem. 14THE GREATEST COMMON DENOMINATOR PROBLEM Write a function named...

    C++ I do not understand this problem. 14THE GREATEST COMMON DENOMINATOR PROBLEM Write a function named god() that accepts two integers as input parameters and returns the greatest common divisor of the two numbers. The greatest common divisor (GCD) of two integers, a and b, is the largest integer that is a factor of both a and b. The GCD of any number and 1 is 1, and the GCD of any number and o is that number. One efficient...

  • can somebody help me with this exercise 5 Euclidean algorithm The largest common divisor (gcd) of...

    can somebody help me with this exercise 5 Euclidean algorithm The largest common divisor (gcd) of two positive integers p and q can be given by the Euclid's algorithm explained in the lecture will be determined. · Write a function gcdIterative that uses the largest common divisor of p and q Calculates loop structure and returns. Use the pseudocode given in the lecture as a starting point and implement it as directly as possible into a C ++ program. Use...

  • write code using void function i need the code in C++ but make sire u solve...

    write code using void function i need the code in C++ but make sire u solve by using void function visor (GCD) of two integers is the largest nacd that returns the greatest com- its digits reversed. For example, 5.31 (Greatest Common Divisor) The greatest common divisor (GCD) of two in integer that evenly divides each of the numbers. Write a function gcd that returns the mon divisor of two integers. . . for Numeric Grades) Write a function qualityPoints...

  • IN PYTHON Write a recursive function for Euclid's algorithm to find the greatest common divisor (gcd)...

    IN PYTHON Write a recursive function for Euclid's algorithm to find the greatest common divisor (gcd) of two positive integers. gcd is the largest integer that divides evenly into both of them. For example, the gcd(102, 68) = 34. You may recall learning about the greatest common divisor when you learned to reduce fractions. For example, we can simplify 68/102 to 2/3 by dividing both numerator and denominator by 34, their gcd. Finding the gcd of huge numbers is an...

  • Extended Euclidian Algorithm (page 4 of last lecture, more on algorithms) Write code that asks for...

    Extended Euclidian Algorithm (page 4 of last lecture, more on algorithms) Write code that asks for and gets two integers, then computes and displays their greatest common divisor using the Extended Euclidian Algorithm (EEA). The EEA should be implemented as a function that takes two integers are arguments and prints their GCD.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT