predicting a divide overflow.
predicting a divide overflow.
(OP)
let's say you got this code:
; 20002h \ 2.
mov ax,2
mov dx,ax
mov bx,ax
div bx
result would be 10001h, which ofcourse does not fit in ax:
a divide overflow error is generated.
Is it possible to predict a divide overflow before it
occurs?
; 20002h \ 2.
mov ax,2
mov dx,ax
mov bx,ax
div bx
result would be 10001h, which ofcourse does not fit in ax:
a divide overflow error is generated.
Is it possible to predict a divide overflow before it
occurs?

Talk To Other Members
RE: predicting a divide overflow.
overflow.
mov ax,2
mov dx,ax
mov bx,2
cmp dx,bx
jae error
div bx
ok:
error:
succes, Tessa
RE: predicting a divide overflow.
I'm not a math person myself, so I am strugling with the
logic behind it. But I have executed some experimental code
based on your example and it seems to work fine.
thank you.
RE: predicting a divide overflow.
100.000/10 gives 10.000 if you now look at the
three zeros afther the dot then that is the ax register
and the 100 is the dx register.
by dividing you see that afther the division ax can't hold the whole 10.000.
so when you divide the 100.000 by 200 it gives .500 and that can be holded in ax.
try it with dividing by 100 and the result will be 1.000
with is just 1 to much to hold since the maximum in this
exxample is 999
I hope this explaince the arithmetic behind it a bit.
succes, Tessa
RE: predicting a divide overflow.
relationship between dx and bx was, and why bx should be
greater than dx in order to divide without an overflow.
But it can be explained by dividing the high order word
of a 32 bit dividend (dx:ax) with a 16 bit value (bx).
So let's leave out ax and concentrate on dx only:
; dx div bx
2 div 1 = 1 ;overflow.
2 div 2 = 1 ;overflow.
2 div 3 = 0 ;no overflow (quotient fits in 16 bit).
btw, I think this error checking code (for me at least) is
a bit clearer:
cmp bx,dx
jbe error
RE: predicting a divide overflow.
Tessa
RE: predicting a divide overflow.
RE: predicting a divide overflow.
the time computers had a huged lag of memory.
If you want to calculate the mean value of a lot of
numbers, as for administration purposes, you add up the
numbers in the double register set and then divide it by
the number count.
In this way you can add 64k numbers of a maximum of 64k
and it will still fit into the final calculation.
Then you can also use the remainder the refine your
outcom to as mutch decimal digits as needed.
So 100 times 30.000 will fit in the dx:ax pair and the result of 30.000 times 100 divide by 100 will still represent the correct answer.
100*30000 3.000.000
--------- = --------- = 3.000
100 100
Hopefully this clears things up a bit.
Tessa