loops - How do I program a greatest common divisor program is 80x86 assembly? -
I know that there are different ways to find two numbers GCD, but I want to know the best Ordinances have been ordered and how do I apply the method in this program?
Even what I have so far:
.586 .MODEL FLAT is included io.h; Header file for input / output. STACK 4096 .DATA number1 DWORD? Number 2 DWORD? Prompt1 byte "Enter an integer for x", 0 prompt2 byte "Enter an integer for Y", 0 string byte 40 DUP (?) ResultLbl byte is "the largest common denominator of x and y", 0 gcd byte 11 dup , 0 .CODE _MainProc PROC input prompt1, string, 40 atod string mov number 1, eax input prompt2, string, 40 atod string mov number 2, EDX mov eax, number 1 mov EDX, number 2 get_gcd (?): Xchg eax, EDX CMP eax, EDX JB Get_GCD sub eax, EDX test EDX, EDX JNZ Get_GCD retired dtoa gcd, EDX output resultLbl, gcd mov eax, 0 mov EDX, 0 retired _MainProc ENDP the ending; End of source code I run it and nothing happens.
Remove the ANT after jnz Get_GCD and before dETO. Euclid subtraction algorithm can be truncated:
; ; Eax and EDX numbers are gcd0: CMP EDX, eax; EDX = small number jb gcd1 xchg eax, edx gcd1: sub eax, edx; Subtract smaller than JNZ gcd0; Loop if it did not; ; ADX = GCD Note that the worst case for the above loop is eax = 0xffffffff and edx = 1, where it takes 4 billion loops to complete Euclid's modulo algorithm below Shown, uses the partition, but the worst case number of loop n is: n & lt; = 5 logs 10 (small number) or n & lt; = 1.50515 Log 2 (small number) For 32-bit unsigned integers, the worst position is two Fibonacci numbers, 1836311 9 03 and + 2971215073 (gcd = 1), the place where many loops = 45 which is. & Lt; = 5 log10 (+1836311 9 03) (~ = 46.32)
Euclid modulo method:
; ; Eax and EBX numbers are CMP EBX, eax; EBX = small number jb gcd0 xchg eax, ebx gcd0: xor edx, edx; Split: Large / small div EBX mov eax, EBX; Eax = new big (small) mov ebx, adx; EBX = New small (new balance) or EBX, EBX; New small if loop! = 0 GNG GCD 0; ; Eax = GCD
Comments
Post a Comment