-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgcd.c
29 lines (24 loc) · 854 Bytes
/
gcd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
int gcd( int a, int b ) {
int result ;
/* Compute Greatest Common Divisor using Euclid's Algorithm */
__asm__ __volatile__ ( "movl %1, %%eax;"
"movl %2, %%ebx;"
"CONTD: cmpl $0, %%ebx;"
"je DONE;"
"xorl %%edx, %%edx;"
"idivl %%ebx;"
"movl %%ebx, %%eax;"
"movl %%edx, %%ebx;"
"jmp CONTD;"
"DONE: movl %%eax, %0;" : "=g" (result) : "g" (a), "g" (b)
);
return result ;
}
int main() {
int first, second ;
printf( "Enter two integers : " ) ;
scanf( "%d%d", &first, &second );
printf( "GCD of %d & %d is %d\n", first, second, gcd(first, second) ) ;
return 0 ;
}