News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help with Uptime procedure

Started by ecube, November 14, 2006, 09:32:36 PM

Previous topic - Next topic

ecube

I tried converting a simple C++ function for getting your computers uptime but am having trouble

Uptime proc
LOCAL buffer[50]:BYTE
LOCAL total:DWORD
LOCAL days:DWORD
LOCAL hours:DWORD
LOCAL minutes:DWORD

invoke GetTickCount
mov ecx,1000
div ecx
mov total,ecx
mov ecx,86400
div ecx
mov days,ecx

comment ~
   DWORD total = GetTickCount() / 1000 - startup;
   DWORD days = total / 86400;
   DWORD hours = (total % 86400) / 3600;      <------ don't know how to do this
   DWORD minutes = ((total % 86400) % 3600) / 60;  <---or this
~   
invoke wsprintf,addr buffer, CTEXT("%dd %dh %dm"), days, hours, minutes
invoke MessageBox,0,addr buffer,addr buffer,MB_OK
ret
Uptime endp

This would be a nice learning experience for future project if anyone can help, thanks.

ecube

This is what I got, but it doesn't work, just crashes

Uptime proc
LOCAL buffer[50]:BYTE
LOCAL total:DWORD
LOCAL days:DWORD
LOCAL hours:DWORD
LOCAL minutes:DWORD

invoke GetTickCount
;DWORD total = GetTickCount() / 1000
mov ecx,1000
div ecx
mov total,ecx


;DWORD days = total / 86400;
mov eax, total
mov ecx,86400
div ecx
mov days,ecx


;DWORD hours = (total % 86400) / 3600;
xor edx, edx
mov eax, total
mov ecx, 86400
div ecx
mov eax, edx
xor edx, edx
mov ecx, 3600
div ecx
mov hours,ecx


;DWORD minutes = ((total % 86400) % 3600) / 60
xor edx, edx
mov eax, total
mov ecx, 86400
div ecx
mov eax, edx
xor edx, edx
mov ecx, 3600
div ecx
xor edx, edx
mov eax,60
div ecx
mov minutes,ecx

comment ~
DWORD total = GetTickCount() / 1000 - startup;
DWORD days = total / 86400;
DWORD hours = (total % 86400) / 3600;
DWORD minutes = ((total % 86400) % 3600) / 60;
~

@@:
invoke wsprintf,addr buffer, CTEXT("%dd %dh %dm"), days, hours, minutes
invoke MessageBox,0,addr buffer,addr buffer,MB_OK
ret
Uptime endp

ramguru

try this

Uptime proc
LOCAL buffer[50]:BYTE
LOCAL total:DWORD
LOCAL days:DWORD
LOCAL hours:DWORD
LOCAL minutes:DWORD

invoke GetTickCount
;DWORD total = GetTickCount() / 1000
xor edx,edx
mov ecx,1000
div ecx
mov total,eax


;DWORD days = total / 86400;
xor edx,edx
mov eax, total
mov ecx,86400
div ecx
mov days,eax


;DWORD hours = (total % 86400) / 3600;
xor edx, edx
mov eax, total
mov ecx, 86400
div ecx
mov eax, edx
xor edx, edx
mov ecx, 3600
div ecx
mov hours,eax


;DWORD minutes = ((total % 86400) % 3600) / 60
xor edx, edx
mov eax, total
mov ecx, 86400
div ecx
mov eax, edx
xor edx, edx
mov ecx, 3600
div ecx
xor edx, edx
mov eax,60
div ecx
mov minutes,eax

comment ~
DWORD total = GetTickCount() / 1000 - startup;
DWORD days = total / 86400;
DWORD hours = (total % 86400) / 3600;
DWORD minutes = ((total % 86400) % 3600) / 60;
~

@@:
invoke wsprintf,addr buffer, CTEXT("%dd %dh %dm"), days, hours, minutes
invoke MessageBox,0,addr buffer,addr buffer,MB_OK
ret
Uptime endp

ecube


Tedd

Just to point out that you're doing far too much work :P

The first DIV of 86400, results in eax being the result, and edx being the remainder - or, the result of MOD ('%')
Then you go and do the same division again immediately afterwards... to get the same result in edx that you already had in edx ::)
..Equally for 3600 :wink

Keep your results and use them as you go along :U
No snowflake in an avalanche feels responsible.