Hello
now this time i have 2 questions for you :tongue:
first of all..
i made a function that get your computers Ram memory..
the problem is i got 160mb ram, but get 159 in eax, because my code round the value in eax down. so even if the value is 159.56 it become 159.
the question is: how do i add 0,5 to eax, or how can i round it up?

now to the second question
how can i get the computers free diskspace? and how much you have total, in mb or gb



invoke GetDiskFreeSpace,addr szDir,ADDR dwSectorsPerCluster, ADDR dwBytesPerSector, ADDR dwFreeClusters, ADDR dwTotalClusters
mov eax,dwTotalClusters
mov edx,dwSectorsPerCluster
mul edx
mov edx,dwBytesPerSector
mul edx
mov ecx,1024
xor edx,edx
div ecx
xor edx,edx
div ecx
invoke wsprintf,offset SpaceBuf,offset Space,eax
invoke SetDlgItemText,hWnd,1003,addr SpaceBuf

but i'm keep getting wrong values...
Posted on 2003-12-02 12:05:57 by bj1500
try



invoke GetDiskFreeSpace,addr szDir,ADDR dwSectorsPerCluster, ADDR dwBytesPerSector, ADDR dwFreeClusters, ADDR dwTotalClusters
mov eax,dwTotalClusters
mov edx,dwSectorsPerCluster
mul edx
mov edx,dwBytesPerSector
mul edx
mov ecx,1024
xor edx,edx
div ecx
xor edx,edx
div ecx
lea ecx, [eax+1]
or eax, eax
cmovnz eax, ecx
invoke wsprintf,offset SpaceBuf,offset Space,eax
invoke SetDlgItemText,hWnd,1003,addr SpaceBuf

Just a quick "hack".
Posted on 2003-12-02 12:13:59 by roticv
hey, thank you for the quick answear but it dosent work quite well
i get this error:
error A2085: instruction or register not accepted in current CPU mode
on this row:
cmovnz eax, ecx
:(
Posted on 2003-12-02 12:20:30 by bj1500
you want to add 0,5 ?? are you using FPU ??
Posted on 2003-12-02 12:21:43 by AceEmbler

you want to add 0,5 ?? are you using FPU ??


well, i dont know if i'm using FPU :mad:
and yes.. i want to add 0,5 to eax to get the right value
add eax,0.5 dosent work
Posted on 2003-12-02 12:27:31 by bj1500
add eax,5
mov ecx,10
xor edx,edx
div ecx
imul eax,10

this will round up/down to the nearest 10:

164 ->160
169 ->170
155 ->160

this will round up/down to the nearest 32, which you should use:
add eax,16
shr eax,5
shl eax,5
Posted on 2003-12-02 14:13:51 by Ultrano
Hello

well, dont you know any code to round to next whole number? so 155,5 -> 156 and 155,4 -> 155 ?
Posted on 2003-12-02 14:18:11 by bj1500
you say your value is in EAX. How can its value be 155.4 ? In fact, it can be - the data in any storage system can be decoded in any way one wants. So, what is the encoding system that has been used to store data in eax?
if you post the code you use, we'll be able to help you, otherwise you're leaving us guess the system...
Posted on 2003-12-02 14:53:12 by Ultrano
Okey, here you have it:


mov eax, MemSt.dwTotalPhys
xor edx,edx
mov ecx,1024
div ecx
xor edx,edx
div ecx
mov edx,eax
push edx ;save for later use
xor eax,eax


like you see, this code convert bytes to mb...
and then i get the result 159,5 something...
if you want (and can) try to optimez my code :)
i know that i cant code very well (yet :tongue: )
Posted on 2003-12-02 15:14:50 by bj1500
Aha! Now I see why you get such a result (159.4) - you took out a calculator and made the two divisions :)

I have 64MB RAM, and I get as output of the GlobalMemoryStatus function, that you use also, this number:
66551808
but it should be
67108864
the difference is
557056 bytes
.

Maybe this difference is fixed in the PC architecture, I don't know why (I'm a newbie in this), so pls, tell me what's the number that is in .dwTotalPhys . Is it 167215104 ?

in case it is, this will work:


mov eax, MemSt.dwTotalPhys
add eax,557056
shr eax,20


But in case it isn't then you should think in another way - can someone have a random amount of RAM? Not really. And if he did, he'd be one on several millions and he'd know how much ram he has. So, you just need the care about ordinary PCs. The minimum separate ram is 32MB, let's assume it's 16 for safer
so, we'll have these possibilities: 16,32,48,64,....256,.....
and the way you can calculate it easily is:



mov eax, MemSt.dwTotalPhys
shr eax,20
add eax,8
shr eax,4
shl eax,4


or if you want to fix it to a megabyte boundary:


mov eax, MemSt.dwTotalPhys
add eax,512*1024
shr eax,20



cheers :grin:
Posted on 2003-12-02 15:48:55 by Ultrano
use ".686".

PS: there is no such thing as decimal place when you are using "div" or "idiv". The remainder is stored in edx. So if the value in edx is more than half the number you are dividing by, you round it up.
Posted on 2003-12-03 09:11:02 by roticv
hello thank you for all your help..
this is my "roundcode" right now



cmp edx,512
JB @End
inc eax
@End: ;do nothing, just continue


:alright:
Posted on 2003-12-03 12:33:53 by bj1500
If you do not want the jcc,


cmp edx, 512
cmc
adc eax, 0
Posted on 2003-12-03 19:29:00 by roticv
i have the same problem in my code for getting ram.. i have 256 but my code says 255...on my other computer it says 127 instead of 128
Posted on 2003-12-03 22:10:25 by illwill
Perhaps the various reserved memory ranges have been subtracted from the amount of physical memory?
Posted on 2003-12-04 06:54:51 by f0dder