+ Reply to Thread
Results 1 to 2 of 2

Thread: divide positive number by negative number

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    12

    divide positive number by negative number

    Hi , i am trying to divide a positive number by a negative number , the problem is when I input a positive number being divided by a negative value, it wont divide at all.
    Here is att syntax :
    Code:
    movsss $imm/%reg %reg/mem move, sign extend 231 movzss $imm/%reg %reg/mem move, zero extend
    But i need the intel syntax , anyway here is my code :
    Code:
    xor rdx, rdx
    mov rax, [input1]
    mov rcx, [input2]
    idiv rcx
    Could you help me to divide a positive number by negative number

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    45
    If the divisor is a signed 64-bit value, you don't need to do anything with it. Likewise, if the dividend is a signed 128-bit value, you don't need to do anything with it, just load the top 64 bits of it into rdx and the low 64 bits into rax.
    You need to use that code :
    Code:
    mov rax, [input]
    cqo ; sign extends rax into rdx:rax
    mov rcx, [input2]
    idiv rcx

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts