Hi Guys
Guess this has been as ked a million times - probably you have a good FAQ about this but there are so many great FAQs on this board I probably can't see the wood for the trees

My question is about the use of [] to specify the address

From various Iczelion tutorials:


invoke CreateWindowEx,NULL,\
                ADDR ClassName,\
                ADDR AppName,\
    mov  hwnd,eax
    invoke ShowWindow, hwnd,CmdShow              ; display our window on desktop

I'm quite happy with that - we store the returned Handle in hwnd, then use the data stored at address hwnd as a parameter to the ShowWindow procedure.

Now this is from another Tutorial (MadWizard.org)

    hSocket    dd  ?

    invoke  socket, AF_INET, SOCK_STREAM, IPPROTO_TCP
    mov    , eax

Why do we require here the square brackets around hSocket??  This seems to be saying "move the contents of eax to the contents of the address hsocket" which from the best I can work out would be the same thing without the square bracket as Iczelion used in the above example.

Also from Madwizard tutorials..

invoke closesocket,

Isn't that the same as.....

invoke closesocket, hsocket

meaning "the data stored at address hSocket"
As opposed to...

invoke closesocket, offset hSocket

which would make the call (incorrectly) with the address of hSocket.

So my question is - are these [] there for any reason other than "for show"? Otherwise I'm seriously misunderstanding all of this  :shock:
Posted on 2005-09-19 04:29:31 by dicky96
meaning depends on compiler you are using.

in masm:
and hSocket means "value, stored in hSocket"
offset hSocket and addr hSocket means "offset of variable hSocket"
(use addr when runtime calculation needed, eg. stack var)

in fasm:
means "value, stored in hSocket"
hSocket means "offset of variable hSocket"
Posted on 2005-09-19 04:50:46 by Shoo
Thanks Shoo
I'm using masm so can see why they are both the same (which I had figured myself) - but now u mention other assemblers I also see why the [] was used in the madwizard tutorial. 

Actually I think it makes the source code a little more readable that way so may adopt it myself.

Great concise answer :)
Posted on 2005-09-19 05:06:48 by dicky96

Actually I think it makes the source code a little more readable that way so may adopt it myself.

In my opinion too. It's required when using registers anyway, and it makes it easier to port code over to other assemblers.
Posted on 2005-09-19 05:57:55 by f0dder
I been a little sketchy on the usage of [ and ] too, after a whole mess of reading I finnaly figured it out lol but I do have 1 question though for f0dder,  what did you mean when you said
It's required when using registers anyway

Posted on 2005-09-22 23:37:42 by EtErNiTy
he ment this:
in masm mov ,eax and mov MyVar,eax are same,
but mov ,eax and mov ebx,eax are still differ - in first case value of eax is stored into memory by offset in ebx, in second case it is stored just into ebx
Posted on 2005-09-23 00:26:04 by Shoo
oooh I got ya, so then that answers that.. I knew how the 2nd opperand brackets worked, but I always wondered what would happen if you tried to store a memory into the "string" of something..
Posted on 2005-09-23 01:29:12 by EtErNiTy
I moved this to the WinASM Main forum because it has more to do with general Win32 assembly than it has to do wtih a specific error/problem with one of Icz's Tuts.
Posted on 2005-09-23 10:20:58 by SpooK