I have a variable initialised with 0 in the .data section and want to change its value like this:
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???
mov eax,OFFSET var ... mov ,edx
w116, Use lea :-
I think that right, but I normally use:-
lea eax,var mov ,edx
which works fine, there's no need to get the address and use a register to change it. Umbongo
umbongo, I just tried your suggestion and the same error occures :mad: Please help me!!! of course you´re right with
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
w116, ok, I just tried :-
and it worked fine, try that. umbongo
.data StartTime dd 0 .code lea eax, mov ,edx
umbongo, thank you, it works fine now!!!
For global variables (IE, those defined in .data)
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:
lea eax, MyVar mov eax, OFFSET myVar
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 MyVar, eax mov , eax
Hope this explains a few things :-) --------------------------------- "I'm normally not a praying man, but if you're up there, please save me Superman!"
mov ecx, eax ; move eax to ecx mov , eax ; move eax to the address pointed to by ecx