0

i have a problem with assembler program x86, 32 bit, gas. I would like to code pgcd.

Here the code. When I execute it, it loops forever.

With gdb, i see the instruction movl $diviseur,dividende is problematic. But I don't understand why.

I tested my code on Debian 9.

        .data
dividende:
        .long  21
diviseur:
        .long 14
mresul:
        .space 8

        .text
        .globl _start

_start:
        movl $dividende,%eax
        movl $diviseur,%ebx
        cdq
        div %ebx
        movl $diviseur,dividende
        movl %edx,diviseur
        cmp $0,%edx
        jnz _start

        movl %ebx,mresul

done:
        movl $0,%ebx
        movl $1,%eax
        int $0x80

the result should have been 7

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
khenty
  • 9
  • 1
  • 1
    Storing the address of `$diviseur` into the memory at `dividende` is unlikely to be useful. Just use registers, that's what they're for. – Peter Cordes Jul 30 '19 at 21:16
  • @Peter Cordes, thank you for your help. using registers helps me to see errors – khenty Jul 30 '19 at 21:46
  • 1
    In particular this instruction doesn't do what you think it does: `movl $diviseur,dividende` moves the address of `diviseur` to the memory location `dividende` – Michael Petch Jul 30 '19 at 21:54
  • 1
    @Michael Petch Thank, your comment was helpful – khenty Jul 31 '19 at 21:23
  • Ok, it works. This code '.data dividende: .long 13481754 diviseur: .long 1234715 .text .globl _start _start: movl dividende,%eax movl diviseur,%ebx boucle: cdq div %ebx cmp $0,%edx jz aff movl %ebx,%eax movl %edx,%ebx jmp boucle aff: movl %ebx,%ecx done: movl $0,%ebx movl $1,%eax int $0x80 ' returns 19. Thanks for your help. It's resolved – khenty Jul 31 '19 at 21:45

0 Answers0