In assembly language if we use
mov eax, dword ptr[ebx]
then it means copy the value pointed by ebx (ebx contains the address value, not the actual value, this instruction copies the actual value in the address)?
If we use
mov eax, dword ptr[some_variable]
then it means copy the value of variable "some_variable" itself to eax, not copy the value pointed by variable "some_variable"?
Is my understanding correct?
If yes, I'm confused why the same assembly instruction has two different meansings - in the first case there is a level of indirection, but in the second there is no additional level of indirection.
Any comment?
EDIT:
Not every [] does not taking any effect, for example, instruction xchg will take a level of in-direction, which loads value pointed by edx.
Whole source code could be found from,
http://www.codeproject.com/KB/threads/spinlocks.aspx
#ifdef WIN32
inline int CPP_SpinLock::TestAndSet(int* targetAddress, int nValue)
{
__asm {
mov edx, dword ptr [pTargetAddress]
mov eax, nValue
lock xchg eax, dword ptr [edx]
}
}
#endif // WIN32