// Compute the greatest common divisor of two integers using Euclid's algorithm.

#include <iostream>

using namespace std;

 

int main(int argc, char *argv[]) {

     int dog, cat, cow, answer;

 

     cout << "Enter two numbers >";

     cin >> dog;

     cin >> cat;

/*

     cow = dog;

     do {

           dog = cat;

           cat = cow;

           cow = dog - cat * (dog / cat);

     } while (cow != 0);

     answer = cat;

 

*/

     _asm {

           mov   ebx, dog    ; EBX always contains current dog

           mov   ecx, cat    ; ECX always contains current cat

again:     mov   edx, 0      ; clear EDX for division

           mov   eax, ebx    ; move dog to EAX

           idiv  ecx         ; EAX = dog / cat

           imul  ecx         ; EAX = cat * (dog / cat)

           mov   edx, ebx    ; EDX = current dog

           sub   edx, eax    ; EDX = dog - cat * (dog / cat)

           jz    done        ; if zero then we are done

           mov   ebx, ecx    ; dog = cat

           mov   ecx, edx    ; cat = cow

           jmp   again       ; repeat

done:      mov   answer, ecx ; save result

     }

 

     cout << "The GCD is " << answer << endl;

     return 0;

}