Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MASM Assmebly Language x86 Processor: Greatest Common Divisor Program Hello Cheg

ID: 3597217 • Letter: M

Question

MASM Assmebly Language x86 Processor: Greatest Common Divisor Program

Hello Chegg experts, this is one of my programming assignments for MASM assembly language x86 Processor.

I really desperately need your help on this!! Also use Irvine32 library.

Here is the assignment:

(If you can't see the picture just read the assignment below the picture)

Greatest_Common_Divisor (Chapter 7, Pr 6)

The greatest common divisor of two integers is the largest integer that will evenly divide both integers. Refer to Euclid's algorithm. The algorithm involves integer division in a loop, described by the C++ code:

Implement this function in assembly language. Write a non-recursive procedure CalcGcd to calculate the GCD of two integers received from eax and ebx, and return EAX as GCD calculated for display. This is an example in action:

The program will be run like this:

Even when a negative entered.

An alternative implementation (not required) is to use subtractions, as see from Using Euclid's algorithm.

I would really appreciate your help on this.

Thank you in advance..

     int GCD(int x, int y)     {        x = abs(x); // absolute value        y = abs(y);          do         {           int n = x % y;           x = y;           y = n;        }         while y > 0;          return x;     }  
Greatest_Common Divisor (Chapter 7, Pr 6) The greatest common divisor of two integers is the largest integer that will evenly divide both integers. Refer to Euclid's algorithm The algorithm involves integer division in a loop, described by the C++ code int GCD (int x, int y) absolute value xabs (x) y = abs (y): do while y>0: return x Implement this function in assembly language. Write a non-recursive procedure CalcGcd to calculate the GCD of two integers received from eax and ebx, and return EAX as GCD calculated for display. This is an example in action 10 10 24 10 24 10 The program will be run like this C:TeachingCSCI241chO7Debng>ch07 06 Enter a 32 bit number: 10 Enter a 32 bit number: 24 Greatest common divisor is: 2 C:TeachingCSCI2411cho7Debng ch07 06 Enter a 32 bit nmnber: -100 Enter a 32 bit number: 48 Greatest common divisor is: 4 Even when a negative entered An alternative implementation (not required) is to use subtractions, as see from Using Euclid's aloorithm

Explanation / Answer

section .data

   prompt x 13, 10, 'First number:','$'

   prompt y 13,10, 'Second number:', '$'

   msg db, ‘The GCD of two numbers are’, eax

section .text

global _start

_start:          

mov eax,x

mov ebx,y

_gcd:

                cmp dword [ebx+12], 0

je .BaseCase

.BaseCase:

mov eax, [ebx+8]

recurse:

                mov eax, [ebx+8]

                xor edx, edx     

            div dword [ebx+12]

              push edx       

             mov eax, [ebx+12]

              push eax      

           call _gcd     

           leave    

          ret

.BaseCase:

            mov eax, [ebp+8]