The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: stbfish on September 20, 2009, 01:15:18 AM

Title: when should i use [ ]
Post by: stbfish on September 20, 2009, 01:15:18 AM
Hi
;...
LOCAL   wcx:WNDCLASSEX

mov   D[wcx.lpszMenuName],IDM_MENU

mov          wcx.lpszMenuName,IDM_MENU

i saw two different way coding as above.
they both working. i am confused with [] and the D before it.
when should i use [], in which way?

thanks
Title: Re: when should i use [ ]
Post by: BogdanOntanu on September 20, 2009, 07:06:54 AM
Hi,

About []
=========

Yes this [] issue is one of the few confusions one has at start of ASM programming.

Basically you should always use [] around variable names. If you check with a debugger you will see that this is what is actually encoded.

However MASM helps you a little and does allow you to omit the [] most of the times but no always.

For example you must always use [] around registers used as pointers like: mov [esi+4],eax.

Basically [] translates as "The content at ..."


About the "D"
===========
The "D" there looks like a GoAsm syntax ... OR it could be a macro meaning DWORD PTR.

Again you must specify the size of the data type you want to access when using plain numbers because the assembler has no other way of knowing the data type/size

For example: mov dword ptr [esi+8],3. Here you need to say "dword ptr" because the assembler does not know the data size. The "3" could be a byte or a word or a dword or a qword (in 64 bits).

Again MASM will help you when it knows the data size and then you can omit typing such info.
For example:
mov [esi], eax ; the assembler knows the size to be 32 bits because of eax
mov [esi+MY_STRUCT.my_word_member],1 ; here the assembler knows the size because of MY_STRUC

Different assemblers have different syntax and rules for those issues. It does not help to mix multiple assemblers at start.
Title: Re: when should i use [ ]
Post by: stbfish on September 20, 2009, 07:36:23 AM
BogdanOntanu

Thank you, I got it. :U