I am trying to get to grips with MASM32 and am confused by the following:
I thought that brackets were used for indirection so if I have the a pre-defined variable
.data
item dd 42
then
mov ebx, item
would put the contents of 'item', i.e. the number 42, into ebx and
mov ebx, [item]
would put the address of 'item', i.e. where the 42 is stored, into ebx.
But the following code in a console app:
mov ebx, item
invoke dwtoa, ebx, ADDR valuestr
invoke StdOut, ADDR valuestr
mov ebx, [item]
invoke dwtoa, ebx, ADDR valuestr
invoke StdOut, ADDR valuestr
prints 42 twice. To get the address of 'item' I seem to need
mov ebx, [OFFSET item]
invoke dwtoa, ebx, ADDR valuestr
invoke StdOut, ADDR valuestr
Can anybody explain what square brackets are for in MASM, or point me at a good reference.
var2 dword var1
assembles to the address ofvar1
. This is the only sane behaviour, becausevar1
could beextern
, making its contents unavailable at assemble time. Fortunately,offset var1
is allowed in that context, so you can always use unambiguous notation. – Shores