Greatest Common_Divisor (Chapter 7, Pr 6) The greatest common divisor of two int
ID: 3596036 • Letter: G
Question
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 ccD (int x, int y) ·abs(x); // absolute value yabs (y) do while y> 0 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 24 10 10 10 24 10 The program will be run like this Enter 32 bit numbeE 10 Enter a 32 bit number: 24 Greatest connoa divisor is: 2 Enter a 32 bit number:-100 Enter a 32 bit numbeE: 48 Greatest conmon divisor is: 4 Even when a negative entered An alternative implementation (not required) is to use subtractions, as see from Using Euclid's algorithm topExplanation / 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]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.