Re: DIV overflow




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 ?


.



Relevant Pages

  • Re: DIV overflow
    ... Best solution would be to avoid DIV at all, ... word divisor;if you want a 16-bit divisor ... Better replace CDQ with XOR edx,edx for UNsigned DIV. ...
    (alt.lang.asm)
  • Re: [PHP] Word Wrap on highlight_file
    ... Tom Chubb schreef: ... doesn't mess up the size of my table div? ... not to mention that 'table div' doesn't make much sense as a concept. ... files with a $ext extension! ...
    (php.general)