Re: DIV overflow
- From: Brian <stringchopperREMOVEALLCAPS@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 31 Mar 2007 13:02:58 -0400
On Sat, 31 Mar 2007 18:22:12 +0200, "Wolfgang Kern" <nowhere@xxxxxxxx>
wrote:
we are thorough :)
Hello Brian,
What are good solutions to preventing DIV overflow?
Best solution would be to avoid DIV at all,
but unfortunately not always very practical.
An easy way is to always have dx just a sign extension of ax,
so for your example better use 32-bit DIV.
MOVZX ebx, word divisor ;if you want a 16-bit divisor
MOV eax, dword dividend
CDQ ;edx=Sign eax 0 or -1 (becomes 0 yet)
DIV ebx ;cannot overflow then
Better replace CDQ with XOR edx,edx for UNsigned DIV.
__
wolfgang
:) we always post it twice ?
so is the sign extension necessary with unsigned division? Also, in
the above, you say "sign extension" but have "MOVZX"... you meant
"MOVSX", right?
--
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
.
- Follow-Ups:
- Re: DIV overflow
- From: Wolfgang Kern
- Re: DIV overflow
- References:
- DIV overflow
- From: Brian
- Re: DIV overflow
- From: Wolfgang Kern
- Re: DIV overflow
- From: Wolfgang Kern
- DIV overflow
- Prev by Date: Re: ascii to tword - help
- Next by Date: Re: DIV overflow
- Previous by thread: Re: DIV overflow
- Next by thread: Re: DIV overflow
- Index(es):