DIV overflow



Hello All (und Hallo Herbert der fremdspracher),

What are good solutions to preventing DIV overflow?

If I have:

INCLUDE Irvine32.inc
..data
dividend DWORD 20001000h
divisor WORD 1000h

..code
main PROC
mov dx, WORD PTR dividend + 2
mov ax, WORD PTR dividend
mov bx, divisor
div bx ;<== overflow here, ax not big enough
exit
main ENDP
END main

.... here my quotient register, AX, is not big enough to hold
20001h. Is my best solution to use a 64-bit dividend, EDX:EAX and
make the divisor a DWORD in ebx, instead of WORD in bx... like so:

dividend DWORD 20001000h
divisor DWORD 00001000h

..code
main PROC
mov edx, 0
mov eax, DWORD PTR dividend
mov ebx, divisor
div ebx
exit
main ENDP
END main

Is it best just to pick a large size register combination for all
division to avoid overflow?

--
thanks,
Brian
To the best of my knowledge, I have:
1) asked a question specifically related to this newsgroup
2) not used my email to request answers be sent there
3) not top-posted
4) not used bad grammar that would make me appear more stupider
.



Relevant Pages