The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: James Ladd on March 06, 2005, 12:21:17 AM

Title: addressing array elements ...
Post by: James Ladd on March 06, 2005, 12:21:17 AM
I have the following:

    local events:WSANETWORKEVENTS
    local watch[2]:WSAEVENT

What I need to do is set handle1 into watch[0] and handle2 into watch[1] but the
correct way to do it eascapes me right now.
Can someone help please?
Rgs, striker
Title: Re: addressing array elements ...
Post by: sluggy on March 06, 2005, 12:36:47 AM
Something like this:


   assume esi : ptr WSANETWORKEVENTS
   lea esi, <your array name>                  ;point to the first struct in the array
   mov eax, <your event>
   mov esi.lNetworkEvents, eax

   add esi, sizeof WSANETWORKEVENTS   ;point to the second struct in the array
   mov eax, <your event>
   mov esi.lNetworkEvents, eax

   assume esi : nothing


Of course this can be made to look a lot prettier in your real code  :P
Title: Re: addressing array elements ...
Post by: James Ladd on March 06, 2005, 12:55:45 AM
Sluggy,
Thanks. Its not exactly what i wanted but it did answer my question.
This is what I have now

    local watch[2]:WSAEVENT
    :
    lea esi, watch
    mov esi, handle1
    add esi, sizeof WSAEVENT
    mov esi, handle2

Ta.
Rgs, striker
Title: Re: addressing array elements ...
Post by: donkey on March 06, 2005, 01:24:24 AM
Hi,

Shouldn't it be...

    local watch[2]:WSAEVENT
    :
    lea esi, watch
    mov [esi], handle1
    add esi, sizeof WSAEVENT
    mov [esi], handle2


You would have to dereference the address contained in ESI in order to mov the data into the right memory buffer.
Title: Re: addressing array elements ...
Post by: James Ladd on March 06, 2005, 01:38:27 AM
Donkey,
When you say "Shouldnt it be" then most likely it should be.
Ill change what I have to what you suggest coz what I have dont work. :(
Thanks Donkey.

ps - im always getting [reg] and reg confused.
Title: Re: addressing array elements ...
Post by: donkey on March 06, 2005, 01:58:09 AM
Hi Striker,

MASM adds the braces in some cases and not in others, that is what we mean in the GoAsm community when we say the syntax is ambiguous. In GoAsm which is much more explicit you would be required to enclose all memory based labels in braces so you get used to it much faster. This isn't to say that there is anything wrong with the way MASM does it, simply that the lack of braces on memory labels but requiring them for registers is an ambiguous situation. When I program in MASM I usually add the braces anyway, it helps me to differentiate between constants, direct to reg and memory based operations.
Title: Re: addressing array elements ...
Post by: James Ladd on March 06, 2005, 02:23:11 AM
Donkey,
I started with goASM and I love it, however, for my current project its MASM as I want to give something to that community.
I dont think the work will be as accepted if it were for goASM.
Rgs, Striker.
Title: Re: addressing array elements ...
Post by: Rifleman on March 06, 2005, 04:08:17 PM
Donkey,
If I ever move to GoASM, and it looks like I am going to, it will be because of that one very frustrating point.  After all this time, you would think that MASM would have been rewritten to solve this silly ambiguity!  Sorry to interrupt, you just struck a chord, as it were.

Paul