I have written this code to convert a numbr of seconds into minutes and seconds, concatenate them onto one string of this form


and print to a static text.

However, when I run the code i counts like this

then after sixty seconds
and so on.

The code is

xor edx,edx
mov ecx,60
div ecx
invoke dwtoa,eax,addr Mins
invoke dwtoa,edx,addr Secs
invoke szMultiCat,3,addr CurrentTime, addr Mins, addr Colon, addr Secs
invoke GetDlgItem,dhWnd,IDC_STC1
invoke SetWindowText,eax, addr CurrentTime
mov edx,0
mov CurrentTime,NULL

where to begin with, eax holds the current number of seconds and IDC_STC1 is where the MINS:SECS string is going.
Now I understand that after

xor edx,edx
mov ecx,60
div ecx

eax holds the quotient of the number of seconds divided by 60 (the minutes) and edx should hold the remainder (the number of seconds), but after 58 seconds, edx seems to give up.

Can anyone shed any light onthe problem or suggest a simpler method of doing this task?


Posted on 2003-10-13 14:16:01 by spu8ajc
The function may not preserve the value of edx, it is not one of the "must be preserved for windows" registers (these are ebx, esi, and edi FYI).

Try pushing the value of edx, then pop it, or if speed is more important you can use the following code (at the expense of readability):

; Push the arguments for the Secs early to avoid corruption of edx in the function call
push Offset Secs ; If Secs is global
; lea ecx, Secs ; If Secs is local
; push ecx
push edx

push Offset Mins ; If Mins is global
; lea ecx, Mins ; If Mins is local
; push ecx
push eax
call dwtoa ; Mins

call dwtoa ; Secs

Posted on 2003-10-13 16:30:38 by Mirno
Nope, i tried that but it still behaves as before. I really cant see what is wrong with the code, especially as it performs perfectly for the first 60 seconds.

Posted on 2003-10-13 16:42:05 by spu8ajc
I don't know the internals of dwtoa, but it looks like it is zeroing EDX when EAX is not zero. That's to be expected if it is using DIV. Save and restore EDX.
Posted on 2003-10-13 22:55:17 by tenkey
err, not meaning to sound completely thick, but how do i save and then restore edx? I have tried a few things, but I managed to hang windows more times than i can count.

Posted on 2003-10-14 19:07:24 by spu8ajc
Its OK, I've done it. Fantastic works perfrectly.

Thanks for your help

Posted on 2003-10-14 19:15:40 by spu8ajc
I don't know a problem - this attach works properly during (wait a little - I must look) 1496 seconds (24:56). Sometimes troubles can be at any another place of program. Best wish ;)
Posted on 2003-10-28 08:23:15 by Shoo