flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Struct implementation question...

Author
Thread Post new topic Reply to topic
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Hi all!
The question is about 'struct ' macro implementation. For example:

Code:
struct Rec

 Val1 dd ?
 Val2 dd ?

ends

mov eax,[ecx+Rec.Val1] ; <- got Rec.Val1 offset defined

    


In earlier versions of FASM this was achieved by this code:

Code:
struc Rec
{
 .Val1 dd ?
 .Val2 dd ?

 virtual at 0
  Rec Rec
 sizeof.Rec = $ - Rec
 end virtual

}    


But how can i get structure offsets defined now?

Thanks and regards.

_________________
Flat Assembler is the best!
Post 03 Mar 2006, 08:42
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
same way as earlier, but proper way is (and was):
Code:
struc Rec 
{ 
 .Val1 dd ? 
 .Val2 dd ? 
}

 virtual at 0 
  Rec Rec 
 sizeof.Rec = $ - Rec 
 end virtual     
Post 03 Mar 2006, 10:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7755
Location: Kraków, Poland
Tomasz Grysztar
The "struct" macro defines all the offsets automatically, see documentation.
Post 03 Mar 2006, 11:25
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
I know it, Tomasz, it is very powerful macro, thank you, but i need to do it with 'struc' manually.
Thanks and regards.
Post 03 Mar 2006, 13:36
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7755
Location: Kraków, Poland
Tomasz Grysztar
Sorry, I misunderstood your question. Note that except for the "fix" (and some other minor changes) fasm keeps all the old features.
Post 03 Mar 2006, 14:07
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Tomasz, please explain, why this doesn't work and. if it is not hard for you, explain your "struct" macro implementaion. It will be very helpful i think.

Code:
macro ins_field [Name]
{
 forward
   .#Name dd ?
}


struc A
{
 ins_field a,b,c
}

struc B
{
 .aa A
 ins_field a,b,c
}

a A
b B
    


Thanks.

_________________
Flat Assembler is the best!
Post 06 Mar 2006, 06:39
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7755
Location: Kraków, Poland
Tomasz Grysztar
The preceding of dotted symbols by structure name is done only in the lines generated by the structure macro itself - the child macros invoked then by those lines are already independent (thus you can always be sure that with regular macro the symbol starting with dot will stay what it is).
Thus it should be rather done like
Code:
macro ins_field Struc,[Name]
{
 forward
   Struc#.#Name dd ?
}


struc A
{
 ins_field .,a,b,c
}

struc B
{
 .aa A
 ins_field .,a,b,c
}

a A
b B    

As for the "struct" macro explanation, please give me some more time.
Post 06 Mar 2006, 08:49
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Thanks for so quick reply!
As for the time - as much as you need of course Smile
Thanks again, will try to use your answer in my OOP macroses.
Post 06 Mar 2006, 09:37
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Tomasz, excuse me for so much questions, but please explain, how must be implemented such thing:

Code:
macro ins_field str,[Name,Type,Value]
{
 forward
  str#.#Name Type Value
}

struc A
{
 ins_field .,a,dd,?, b,dd,? ,c,db,?
}

struc B
{
 ins_field ., aa,A,, a,dd,?, b,dd,? ,c,db,? ; <- try to declare uninitialize structure here
}

a A
b B     


Thanks.

_________________
Flat Assembler is the best!
Post 06 Mar 2006, 12:12
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Solve this problem, just remember about "enable_xxx" and "purge xxx" technique. But have got another one: why doesn't work this:

Code:
macro enable_ins_field
{
 macro ins_field str,[Name,Type,Value]
 \{
  \forward
   str\#.\#Name Type Value
 \}

}
enable_ins_field

macro A_ins
{
 ins_field .,a,dd,?, b,dd,?, c,db,?
}

struc A
{

 enable_ins_field
 A_ins
 purge ins_field
}

macro B_ins
{
 ins_field .,aa,A, , a1,dd,?, b1,dd,?, c1,db,?
}

struc B
{
 enable_ins_field
 B_ins
 purge ins_field
}

a A
b B    


Thanks.

_________________
Flat Assembler is the best!
Post 06 Mar 2006, 13:36
View user's profile Send private message Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Hi all!
Have another question: why "sizeof" doesn't work in this case?

Code:
macro enable_ins_field
{
 macro ins_field str,[Name,Type,Value]
 \{
  \forward
   str\#.\#Name Type Value
 \}

}

struc A
{
 macro A_ins
 \{
  ins_field .,a,dd,?, b,dd,?, c,db,?
 \}

 enable_ins_field
 A_ins
 purge ins_field
}

struc B
{

 macro B_ins
 \{
  ins_field .,a1,dd,?, b1,dd,?, c1,db,?, aa,A,
 \}

 enable_ins_field
 B_ins
 purge ins_field
}

virtual at 0
 A A
 sizeof.A  =  $ - A
end virtual

virtual at 0
 B B
 sizeof.B  =  $ - B
end virtual    


Thanks and regards.

_________________
Flat Assembler is the best!
Post 09 Mar 2006, 08:33
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7755
Location: Kraków, Poland
Tomasz Grysztar
When you use the "." symbol inside the STRUC macro, the preprocessor abstains from generating the label for structure automatically and leaves it to you. Thus while using the "." somewhere inside the STRUC macro you need to put something like:
Code:
.:    

or
Code:
label .    

in the beginning (or other place you find suitable) of it.

This behavior was introduced to allow declaring the "." label in any way you want, not as it is with automatically generated one.
Post 09 Mar 2006, 09:33
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Thank you, Tomasz! FASM is really the best!
Regards.
Post 10 Mar 2006, 06:35
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.