News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

when should i use [ ]

Started by stbfish, September 20, 2009, 01:15:18 AM

Previous topic - Next topic

stbfish

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

BogdanOntanu

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.
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

stbfish

BogdanOntanu

Thank you, I got it. :U