Search code examples
assemblyx86masm

Remainder of DIV is not in EDX


I have defined num1, num2, and remainder variables as DWORD. I get 2 numbers from the user which are num1, and num2. I'm trying to divide num1 by num2. The numbers I'm using are num1=37 and num2=5

sub    edx,edx    ; Zero edx
mov    eax,num1
mov    ebx,num2
div    ebx
mov    remainder,edx
mov    edx, OFFSET remainder
call   WriteInt

For some reason this prints out 7, which is the quotient, not the remainder. What am I doing wrong here?


Solution

  • Use this.

    mov    edx,0   ; Zero edx
    mov    eax,num1
    mov    ebx,num2
    div    ebx      
    mov    eax,edx     ; EAX = reminder
    call   WriteDec    ; Display 2