flat assembler
Message board for the users of flat assembler.

Index > Main > uninitialised structs,

Author
Thread Post new topic Reply to topic
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1
I want to do the following:
Code:
struc point x,y
   {
   .x  db x
   .y  db y
   }
    

so that I can do:

Code:
varxy   point  1,2
varz   point 
    


where in the second case I want all fields initialised to 0,

now the only way I have found to do this is:

Code:
struc point x,y
   {
   if x eq
      .x  db 0
   else
      .x  db x
   end if

   if y eq
      .y db 0
   else
      .y db y
   end if
   }
    

Confused
but this is quite complicated,
is there a simpler way to do this? Razz

I tried using a macro:
Code:
macro  field x,dz
    {
    if x eq
       .#x  dz 0
    else
       .#x  dz x
    end if
    }

struc  point x,y
   {
   field x,db
   field y,db
   }

    


but fasm didnt accept this Sad , not sure why,
Post 16 Feb 2006, 01:24
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
The good old trick for doing this is:
Code:
struc point x,y
   {
   .x  db x+0
   .y  db y+0
   }    


As for your solution, it didn't work because you used value as if it was the name also. You should do it like:
Code:
macro  field n,dz,v
    {
    if v eq
       n dz 0
    else
       n dz v
    end if
    }

struc  point x,y
   {
   field .x,db,x
   field .y,db,y
   }    

or maybe:
Code:
struc Db v
{ if v eq
   . db 0
  else
   . db v
  end if }

struc point x,y
   {
   .x  Db x
   .y  Db y
   }    
Post 16 Feb 2006, 10:05
View user's profile Send private message Visit poster's website Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
maybe something like this, but I don't know will it work:
struc point x,y
{
.x db x+0
.y db y+0
}
sorry if it would not work.
Post 16 Feb 2006, 10:06
View user's profile Send private message Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1
Tomasz Grysztar wrote:
The good old trick for doing this is:
Code:
struc point x,y
   {
   .x  db x+0
   .y  db y+0
   }    




this trick looks really neat Razz

the other 2 will be useful for understanding how fasm operates,

the 3rd technique with the "." is very unusual,
I havent yet fully understood this one:

say I have:

Code:
xyz   point  3
    


after the first expansion of point will this be translated to:

Code:
xyz
    .x Db 3
    .y Db 
    


and then after the second expansion of Db to:

Code:
xyz 
    .x
    . db 3
    .y
    . db 0
    


Question Question Confused Question Question
Post 16 Feb 2006, 12:52
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
nope, after usage of "a point 5,6" it becomes
Code:
a.x Db 5 
a.y Db 6    


eg. structure name ("a") is prepended to all symbols starting with dot (".x" and ".y"), and macro arguments are replaced by theior values ("x" -> 5, "y" ->6)

Then also inner macros ("Db") are expanded, "a.x Db 5" becomes
Code:
if 5 eq 
 a.x db 0 
else 
 a.x db 5
end if }    


eg. "." is replaced with structure name "a.x", and "v" is replaced by it's value "5". Rest is not preprocessing... "if 5 eq " is false condition so "a.x db 5" gets assembled. In case of empty argument condition would be "if eq" which is true, so "a.x db 0" would be assembled
Post 16 Feb 2006, 13:16
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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.

Powered by rwasa.