From: Wolfgang Kern on

Rick Hodgin wrote:

> The best solution, if you're concerned about occasional overflow
conditions > using 16-bit math, with the desire to return only a 16-bit
quantity, would
> be to write your code like this:
>
> #1 - do normal divide (div 32 bits by 16 bits, result will be 16 bits or
> overflow)
> #2 - check if overflow, if so, go to 4
> #3 - go to 5
> #4 - either recompute divide using larger operands and return 32-bit
value,
> or signal overflow by returning saturated value (all 16 bits set to 1)
> #5 - return result
>
> The best way to avoid overflows is to always use a dividend that is the
same
> size as your divisor. In that way, even if you divide by 1, it will
always
> be at least the same size value (a max 32-bit quantity of the source
value).

Hello Rick,

Check if overflow ?
Unfortunately all (O,S,Z,A,P,C) flags are undefined after DIV/IDIV
and wont tell if the instruction succeeded or not.

Same as Frank asked: Hook exception and check if a DIV/0 occured ?

The only way I know is to check on operands ahead of DIVide.

__
wolfgang




First  |  Prev  | 
Pages: 1 2 3
Prev: ascii to tword - help
Next: Is hex an ascii thing?