I have a variable initialised with 0 in the .data section and want to change its value like this:

mov   eax,OFFSET var
mov   ,edx
But when I execute the program I get an error that tells me "read" could not be performed on the memory. Can anybody help me to solve this problem???
Posted on 2001-04-23 09:24:00 by w116
w116, Use lea :-

lea eax,var
mov ,edx
I think that right, but I normally use:-

mov var,edx
which works fine, there's no need to get the address and use a register to change it. Umbongo
Posted on 2001-04-23 09:51:00 by umbongo
umbongo, I just tried your suggestion and the same error occures :mad: Please help me!!! of course you´re right with

mov   var,eax
but I need to pass the var to a macro and this macro changes the var, and the macro changes another var every time it is called. Thank you
Posted on 2001-04-23 10:30:00 by w116
w116, ok, I just tried :-


StartTime dd 0


lea eax,
mov ,edx

and it worked fine, try that. umbongo
Posted on 2001-04-23 10:41:00 by umbongo
umbongo, thank you, it works fine now!!!
Posted on 2001-04-23 11:00:00 by w116
For global variables (IE, those defined in .data)

lea eax, MyVar
mov eax, OFFSET myVar
are equivalent statements. In fact, earlier versions of MASM (ml.exe) once would optomize the former to the latter. The difference in these statements is how much the compiler knows about address MyVar. If it's known at compile time, either statement is OK. IF the address of MyVar is NOT known at compile time, lea must be used. Why would the location of MyVar not be known at compile time? Mostly if MyVar is a LOCAL variable made on the fly on the stack. Then the address must be computed at runtime, and lea can do this computation (mov can only take a static pointer). Note for a global variable you need not first load the address of MyVar. The following work just fine:

mov MyVar, eax
mov , eax
Perhaps it's a bit sloppy, but MASM assumes you mean the address of a variable in both cases (so it adds the brackets for you). If you think a bit about it, the only thing the variable name COULD mean is the variable's address. However, don't think the same is true with registers:

mov ecx, eax      ; move eax to ecx
mov , eax    ; move eax to the address pointed to by ecx
Hope this explains a few things :-) --------------------------------- "I'm normally not a praying man, but if you're up there, please save me Superman!"
Posted on 2001-04-23 22:05:00 by Ernie