How to resolve the algorithm Greatest common divisor step by step in the x86 Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Greatest common divisor step by step in the x86 Assembly programming language

Table of Contents

Problem Statement

Find the greatest common divisor   (GCD)   of two integers.

Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Greatest common divisor step by step in the x86 Assembly programming language

Source code in the x86 programming language

.text
.global pgcd

pgcd:
        push    %ebp
        mov     %esp, %ebp

        mov     8(%ebp), %eax
        mov     12(%ebp), %ecx
        push    %edx

.loop:
        cmp     $0, %ecx
        je      .end
        xor     %edx, %edx
        div     %ecx
        mov     %ecx, %eax
        mov     %edx, %ecx
        jmp     .loop

.end:
        pop     %edx
        leave
        ret

  

You may also check:How to resolve the algorithm String matching step by step in the Phixmonti programming language
You may also check:How to resolve the algorithm Combinations step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Echo server step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Read a file character by character/UTF8 step by step in the Phix programming language
You may also check:How to resolve the algorithm First-class functions/Use numbers analogously step by step in the Racket programming language