First of all, sorry for the basic questions -- I'm new to assembly language/MASM. I have been very confused with the use of OFFSET, square brackets and de-referencing.
This is my understanding:
Variables/data labels are memory addresses. Square brackets imply a de-reference, so [var] would retrieve the content at address var. MASM instructions automatically dereference memory operands, so the following would both copy the content of var to eax:
MOV eax, var MOV eax, [var]
To move the address of var to a register, one would need to do
MOV reg, OFFSET var
But now it looks like var and [var] are not equivalent anymore:
var DWORD 10h mov esi, OFFSET var mov eax, [esi] ; eax = 10h mov eax, esi ; eax = address of var
This is where my confusion starts. Given dereferencing is always implied, when are square brackets necessary? When are they optional?
In addition, the following would initialize var2 with the address of var1
var1 byte 10h,20h,30h,40h var2 dword var1 var2 dword OFFSET var1 ; equivalent
Now, when does var1 refer to the address? When does it refer to the content?