flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > array of struc with defined data

Author
Thread Post new topic Reply to topic
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
I need a simple way of defining and array of strucs and filling in
the array of strucs with data, and hopefully this can be a future modification of fasm's struc directive

Here is a c example of what I need to do in assembly:
Code:
RECT cliplist[4] = { {0,0,100,100},{200,200,300,300},{400,100,500,200},{500,400,550,450} }    


My solution is this, clumsy, but should work (notice I had to do redo the standard fasm windows RECT struc):
Code:
struc MYRECT a,b,c,d
{
   .left   dd a
   .top    dd b
   .right  dd c
   .bottom dd d
}


  cliplist      MYRECT 0,0,100,100 ;create first RECT structure
                dd 200,200,300,300
                dd 400,100,500,200
                dd 500,400,550,450

[u]and then you would use ecx as an index like so[/u]
mov ecx,sizeof.MYRECT*3 ;fourth rect structure
mov [cliplist.top+ecx],300     


Hopefully this can soon be done in a simple way with the struc directive, maybe something like:
Code:
myrect RECT = [ [0,0,100,100],[200,200,300,300],[400,100,500,200],[500,400,550,450] ]

and then

mov eax,myrect.[3].top ;4th RECT array, variable .top
    


any comments?
MadMatt
Post 24 Jun 2004, 17:33
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
yours way won't be possible, "." and "[","]" have sbosolutely different meaning in FASM. You can make it by defining both struct RECT and macro RECT:
Code:
macro RECT a1,a2,a3,a4
{
  dd a1,a2,a3,a4
}    

and then you can do
Code:
cliplist RECT 0,0,100,100
         RECT 100,100,200,200
    

there are some macros, which define both macro and struc for you, you can find them somewhere in board (but don't know where, sorry)

btw, yours way to do it is okay.
Post 24 Jun 2004, 20:10
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Hello vid,
vid wrote:
yours way won't be possible, "." and "[","]" have sbosolutely different meaning in FASM. You can make it by defining both struct RECT and macro RECT:


1. I know it wouldn't be possible with FASM now. The way I suggested would mean that FASM would have to be modified to handle the data of structs and the accessing method.
2. Accessing individual components your way would be unclear when coding it into assembly.

vid wrote:
there are some macros, which define both macro and struc for you, you can find them somewhere in board (but don't know where, sorry)


I might have those macros somewhere, but this should be a hardcoded feature in fasm for some future time. This would help in making more complex windows/directx/direct3d programming easier and more intuitive.
Madmatt
Post 25 Jun 2004, 00:51
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
don't believe it, to using your method would require to CHANGE (break backward compatiblity) FASM's logic in many things, where it isn't nescessary.
Post 25 Jun 2004, 06:53
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
I agree with you, vid.
Post 25 Jun 2004, 07:41
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
My way above was a suggested way, NOT the only way. There is NO reason why FASM can't have this feature in some future version. Not EVERYTHING can be done in macros. Of course, privalov has the final say on this matter, I simply don't have the time to go through the code and try and figure out where to make the changes, test and debug the thing. It might be a somewhat complex to implement, but I don't think it is impossible. This would make fasm much more powerful for large projects in windows, or smaller projects for that matter.
MadMatt
Post 25 Jun 2004, 08:12
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
It will also make it much less comrehensible ("." behavior will become funny), you will have to change local labels system totally, it would require many changes to preprocessor, "[]" would be used for both array-addressing and memory-addressing etc. etc. thus becoming unclear.

In my opinion you are too used to high level languages, using asm too short, and you still didn't get the "assembly" way of thinking when writing code.
Post 25 Jun 2004, 20:35
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Defining data the way I stated:
Code:
myrect RECT = [ [0,0,100,100],[200,200,300,300],[400,100,500,200],[500,400,550,450] ]    

shouldn't be much of a problem, and shouldn't require major changes to the way fasm does things. Just check for '=' sign after fasm is certain it is a valid 'RECT' struc , and then process and error check the data following it.

Same thing with accessing the data:
Code:
mov eax,myrect[3].top ;4th RECT array, variable .top    

just check if there was a leading '[' if not, then if fasm finds one right next to a variable then must be array of something, so check if valid struc define and process other parts of the struct.

Quote:
In my opinion you are too used to high level languages, using asm too short, and you still didn't get the "assembly" way of thinking when writing code.


I've been writing in assembly more than any other language combined. If the 'assembly way' of doing things means doing every other thing the 'hard confusing way', then you can have it. my code above looks clearer than 'mov eax,[myrect.top+ecx]'. Having 'some' High level features in fasm is a plus, especially when writing windows and mmx/sse/sse2 assembly code, which is the whole reason I'm asking for this.
MadMatt
Post 26 Jun 2004, 04:03
View user's profile Send private message Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
Why not:
Code:
macro _RECT name, x1,y1,x2,y2 {
    name#.left dd x1
    name#.top dd y1
    name#.right dd x2
    name#.bottom dd y2
}

struc RECT [name,x] {
    common
        virtual at $
          .left dd ?
          .top dd ?
          .right dd ?
          .bottom dd ?
        end virtual
        .count = 0
    forward
        _RECT .#name,x
        .count = .count + 1
}

f RECT item1,<0,0,100,100>, item2,<25,25,50,50>, item3,<100,100,200,200>    
This will give:
Code:
f.item1.left
f.item1.top
...
f.item3.right
f.item3.bottom
f.count    
Post 26 Jun 2004, 07:00
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
the way tommy proposed will work, of course, but your's wouldnt.
Quote:

Just check for '=' sign after fasm is certain it is a valid 'RECT' struc

Don't forget struc is just another type of macro, so after checking it is valid RECT structure, it must expand RECT "macro" (or structure - almost same thing).

Really, try to mess with FASM somewhat longer and you will realize why it isn't possible (at least not the way you suggested)
Post 26 Jun 2004, 07:18
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Tommys suggestion is fine, but what about all the other hundreds, (if not thousands) of windows structures, do you want me to redefine each and every one of them too?
using:
Code:
mov eax,myrect[4].top    

Why would this cause fasm trouble? This is good, the compiler does all the calculating, and this code looks more readable than something like:
Code:
mov eax,[myrect.top+ecx]    


Code:
myrect RECT = [ [0,0,100,100],[200,200,300,300],[400,100,500,200],[500,400,550,450] ]    


Is a reasonable request, and doable, and would be useful for setting up (array of) structures quickly with predefined values.
Post 26 Jun 2004, 12:49
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
not with "[]" characters, maybe "<". Using "[" it will be hard to pass argument containing "[" to structure. Also, it will be problem to create names like "myrect[3].a" now
Post 26 Jun 2004, 14:51
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
That sounds good also, whatever makes it the easiest to implement. Actually, the data defining is what I'm really looking for. I thought I would throw in the array access method just for completness. I think I remember some macros that were made a few months ago in the 'macro instructions' forum that does at least some of what I'm looking for. However, It would be better to have these hardcoded into the fasm compiler.
Post 26 Jun 2004, 21:23
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
i don't think so. And be sure that if it can be acheived by macros, then Privalov won't hardcode it into FASM.
Post 27 Jun 2004, 10:00
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S.
madmatt wrote:
Code:
mov eax,myrect[4].top     
the compiler does all the calculating, and this code looks more readable than something like:
Code:
mov eax,[myrect.top+ecx]     

BTW, how will compiler figure out the use of ECX in the first case?
Post 27 Jun 2004, 15:22
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.