Hi. Im getting the free physical memory of the system using GlobalMemoryStatus API. It returns bytes, and I would like KBytes. So I would like to divide by 1024. Here is my code:



div(TotalPhys, ax);

Im moving 2 into AX, then shifting it left 10 times (2^10 = 1024), then using Div. Div is complaining though about "Operand Size Mismatch".

Whats wrong? Thanks. Also, is there a way to use shifts to avoid the Div?
Posted on 2005-01-06 07:23:28 by polyfractal
You should use 32bit registers - so EAX, not AX. As you already seem to know, shifting by 10 can multiply by 1024... shifting 10 in the other direction divides by 1024. So...
Posted on 2005-01-06 07:26:57 by f0dder
Oh, good point. Not sure why I didn't think about that :) I'll try this when I get back to work on it tommorow:

mov(TotalPhys, eax);
shr(10, eax)
mov(eax, TotalPhys)

Thanks again!
Posted on 2005-01-06 09:21:13 by polyfractal