The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: piotrus on April 14, 2007, 05:49:13 PM

Title: integer overflow
Post by: piotrus on April 14, 2007, 05:49:13 PM
When my program goes to 'div X2' it throws an expeption "integer overflow". X2 is a word value (0x00000002 in this case).

...
mov bx, WORD PTR [eax]
xor eax, eax
mov ax, bx
div X2
mov ecx, pEchoBuffer
mov WORD PTR [ecx+esi],ax
...

What is wrong? :)

Thanks in advance,
Peter
Title: Re: integer overflow
Post by: u on April 14, 2007, 06:37:09 PM
do a
xor edx,edx
beforehand. It overflows because you're dividing a large 64-bit value (probably edx>1) by the small 32-bit value.
Title: Re: integer overflow
Post by: piotrus on April 14, 2007, 07:18:49 PM
You were right Ultrano, the value of edx was much more > 1 :)
But it still didn`t work.
I solved the problem by replacing
div X2
with
div WORD PTR X2

Now it works :D