[...]
call GetTickCount

mov ecx, 1000
div ecx ; <-- crashes here
xor edx, edx
mov ecx, 60
div ecx
mov ebx, edx
xor edx, edx
div ecx

invoke wsprintf, addr szTimeBuffer, addr szTimeMask, eax, edx, ebx
[...]


from VC++ debugger:



004019D9 call 00401D20 ; GetTickCount
004019DE mov ecx,3E8h ; 3E8h == 1000
004019E3 div eax,ecx ; <-- crashes here with 'integer overflow'?!
004019E5 xor edx,edx
004019E7 mov ecx,3Ch ; 3Ch == 60
004019EC div eax,ecx
004019EE mov ebx,edx
004019F0 xor edx,edx
004019F2 div eax,ecx
004019F4 push ebx
004019F5 push edx
004019F6 push eax
004019F7 push 403085h ; offset szTimeMask
004019FC push 40BC2Ch ; offset szTimeBuffer
00401A01 call 00401C6C ; wsprintf


Hope someone can help me :)

Edit: I'm using WinXP Pro
Posted on 2002-01-13 09:13:00 by bazik
To let you know to do this:
    call GetTickCount

xor edx,edx
mov ecx, 1000
div ecx
Posted on 2002-01-13 09:40:43 by bitRAKE
Just to elaborate on what bitRake said, you need to 'sign-extend' the edx register before doing a div, as it is used to hold part of the result.
Posted on 2002-01-13 10:02:49 by sluggy
The reason...

when you divide by a 32bit number, it's actually not just EAX that
gets divided. It is the 64-bit EDX:EAX. If you just have random data
in EDX, the result of the division might be too large to put in a 32bit
number, and thus you'll get a division overflow exception.

When working with unsigned numbers, just clear EDX before the
division. With signed numbers, use CDQ (Convert Double to Quad).
Posted on 2002-01-13 11:25:14 by f0dder
Ok, thanx all!
And thanx, f0dder for this explanation! I just forgot this line (did it above the other 2 div's) :stupid:
Posted on 2002-01-13 11:46:59 by bazik
Depending on the accuracy needed, you could divide by 1024 (eg shr eax, 10)
Posted on 2002-01-13 18:38:14 by eet_1024