0

I am traying to make a simple division in x86-64 and when I give input like 4 and 2 the result should look like 4 / 2 = 2 but I am getting 4 / 0 = 0 any ideas ?

4 / 2 = 2 instead I got 4 / 0 = 0

 sub $8, %rsp

        mov $input_format, %rdi
        mov $a, %rax
        mov $b, %rsi
        mov $0, %al
        call scanf

        xor %rdx, %rdx
        mov a, %rax
        mov b, %rsi
        idiv %rsi

        mov $output_format, %rdi
        mov $0, %al
        call printf

        add $8, %rsp
  • Are you single-stepping with a debugger? Your code doesn't put the quotient (in RAX) anywhere; you just overwrite the low byte of it with `mov $0, %al` as part of the calling convention for a variadic function like printf. After the format string in RDI, printf looks in RSI, RDX, and RCX for the next 3 args. (per the standard calling convention.) Your incomplete [mcve] doesn't show your format strings. – Peter Cordes Mar 29 '22 at 03:23
  • Thank you a lot for your answer, mov $0, %al is telling that there is no floating-point number and no more job it does – MsD XXX Mar 29 '22 at 12:20
  • and i do not know where is my second argument – MsD XXX Mar 29 '22 at 12:30
  • Oh right, forgot to add [What are the calling conventions for UNIX & Linux system calls (and user-space functions) on i386 and x86-64](https://stackoverflow.com/q/2535989) as one of the duplicates. Although I did include the arg order in my previous comment; printf's 2nd arg (1st conversion) is in RSI. – Peter Cordes Mar 29 '22 at 19:19

0 Answers0