I have read a lot of examples on 32-bit division and I have seen a lot of,

mov edx, hiword ;load edx with hi word of dividend
mov eax, loword ;load eax with lo word of dividend
mov ebx, divisor ;load ebx with divisor
div ebx ;quotient goes into eax, remainder into edx

I don't understand the hi and low

here is what I got so far, but I don't know where to go for the dividing part.

``````mWrite "Enter for X: "
mov x, eax

mWrite "Enter for Y: "
mov y, eax``````

after that I successfully store my input into variables I declared as DWORD, all the examples I have seen I can't seem to incorporate that logic into my program.

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by NotNull

This is what I got so far, the program bombs when I enter the second number.

Variables:

``````x DWORD ?
y DWORD ?
sum DWORD ?
rem DWORD ?``````

Divide Macro:

``````mDivide MACRO intX:REQ, intY:REQ, intSum:REQ
mWrite "Enter for X: "
mov x, eax

mWrite "Enter for Y: "
mov y, eax

xor edx, edx
mov edx, x
mov ebx, y
div ebx

mov sum, edx

push edx
mov edx, OFFSET intSum
call WriteString
pop edx
call Crlf
ENDM

mDivide x, y, sum``````

With a 32-bit divisor it is divided against the quad-word
in EDX:EAX, quotient is returned in EAX, remainder in EDX.
You said you do not understand the hi and lo part,
they represent the high and low DWORDs of a 64-bit value.
Thus EDX:EAX represent one whole value, EDX representing
the 32 most significant bits and EAX representing the 32
least significant bits, if I got this right.

Here's an example with a 16-bit divisor.
With a 16-bit divisor it is divided against the
DWORD in DX:AX
Lets say we have the value 2147483648d as are
dividend, this is 80000000h.
8000h the high word would go in DX.
0000h the low word would go in AX.

``````MOV DX,8000h
XOR AX,AX
MOV CX,FFFFh
DIV CX               ; DX:AX / CX
; 80000000h / FFFFh = [AX] 8000h [DX] 0000``````

And also do not forget that the quotient cannot be larger
than the destination register.
So when using a 16-bit divisor make sure the quotient
will not be larger than 16-bits, the size of AX.
And when using a 32-bit divisor make sure the quotient
will not be larger than 32-bits, the size of EAX.