Hi,

Suppose I want to declare an array with 64 dwords within an object in ObjAsm. I could use the Array object for this.
But I wonder: Is it possible to use DefineVariable in combination with the pseudo-op DUP, in order to allocate these 64 dwords?

Friendly regards,
mdevries.
Posted on 2006-10-24 04:40:22 by mdevries
Hi
Use the following syntax:

  DefineVariable    MyVar,             dword,      64 dup (0)


Regards,

Biterider
Posted on 2006-10-24 06:13:25 by Biterider
Hi Biterider,

Thanks for your response.

I couldn't find it in the documentation.
So, I thought I had to use a Struct, and then use the Struct as the type, which I didn't want to.

Maybe you could spend a few words on it in the Help file?

Friendly regards,
mdevries.
Posted on 2006-10-24 06:31:00 by mdevries
Hi
Thanks for the feedback. Such comments help me to find week points in the documentation.

Biterider
Posted on 2006-10-24 06:33:57 by Biterider
Hi Biterider,

In my previous question I asked for 64 dwords.

Now, suppose I define a Struct like this.
VELD struct
    Waarde dword 0
    Inhoud dword 0
VELD ends


And I want to allocate 64 of them, using DUP. How do I do that?

I tried this:
DefineVariable  Bord, VELD, 64 DUP {<>}


And this:
DefineVariable  Bord, VELD, 64 DUP ({<>})


And this:
DefineVariable  Bord, VELD, 64 DUP ({})


And some other variations.
But I always get an error in the ObjectEnd line.


If I change the code like this, everything is ok:
DefineVariable  Bord, VELD, {<>}


That's nice, but now I only have 1 instance of the struct, instead of 64.
How do I get my 64 instances, using DUP?

Friendly regards,
mdevries.
Posted on 2006-10-29 16:02:02 by mdevries
Hi mdevries
The instance space you are requesting can not be done this way, but since you can not access them by name, it make no much sense to do it. Instead I suggest to use the following approach

MyStruc struc
  a dword    ?
  b dword    ?
MyStruc ends

...
  DefineVariable    MyVar,  byte,  64*sizeof(MyStruc) dup (0)
...


When you access the variable typecast it to set the structure members, like

lea eax, .MyVar
mov .MyStruc.a, 100


If you need this feature like you described before, I have to write it. Let me know.

Regards,

Biterider
Posted on 2006-10-30 02:02:43 by Biterider
Hi Biterider,

DefineVariable    MyVar,  byte,  64*sizeof(MyStruc) dup (0)


Indead, this is a possible workaround if you want to initialize the allocated space with zero values.

The instance space you are requesting can not be done this way, but since you can not access them by name, it make no much sense to do it.


It makes sense when you allocate the space.
Suppose you don't want to zero the allocated space out, but you want different values to be used for the various elements in the structure.

According to my Masm documentation, you should be able to initialize some or all the elements of the structure.
Normally, if you allocate space using a Struct, Masm copies the data for the various elements from the Struct definition.
While allocating the space, you can override this by giving some or all of the elements a new value, specified within the curly braces.
That gives you a speedup advantage, over initializing the data runtime.

This seems to be not possible in ObjAsm32 the way it is now.

If you need this feature like you described before, I have to write it. Let me know.


That is what I am aiming for.

Friendly regards,
mdevries.
Posted on 2006-10-30 02:37:46 by mdevries
OK, I'll do it.
For the moment, I suggest to write a Startup Bound Method (which is executed only once when the app is started = SysInit) to initialize the object template with the values you want. Each new instance of the object will be initialized with these values.

Regards,

Biterider
Posted on 2006-10-30 03:04:50 by Biterider
Hi Biterider,

OK, I'll do it.

Thanks for that, and for your StartUp advice, which I can use in the meantime.

Friendly regards,
mdevries.
Posted on 2006-10-30 03:53:08 by mdevries
Hi mdevries
Here is an alternative that let you access each structure. Give it a try.

  ...
  Count = 0
  repeat 64
  DefineVariable    MyVar%Count,  MyStruc,  {5,2}
  Count = Count + 1
  endm
  ...


Regards,

Biterider
Posted on 2006-10-30 15:56:26 by Biterider
Hi Biterider,

I haven't tried it yet, but if it looks good.
If I can't get it to work, I'll be in touch.

Friendly regards,
mdevries.
Posted on 2006-10-31 01:58:56 by mdevries
Hi
I changed Demo 2 to show how to use it. Attached the modified files.

Regards,

Biterider
Attachments:
Posted on 2006-10-31 02:31:06 by Biterider