flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > simple "union" macro

Author
Thread Post new topic Reply to topic
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7362
Location: Kraków, Poland
Quite simple but may be useful:
Code:
macro union [def]
 { common size@union = 0
          origin@union = $
   forward virtual
            def
            if $-origin@union > size@union
             size@union = $-origin@union
            end if
           end virtual
   common rb size@union }    

Example of usage:
Code:
union first dd ?, second db ?,  third rw 3    

Can be used in structures, too.
Post 29 Aug 2004, 16:08
View user's profile Send private message Visit poster's website Reply with quote
Foamplast



Joined: 07 May 2004
Posts: 36
Location: Saratov, Russia
Can you explain using the '@' symbol?
Post 02 Sep 2004, 21:04
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7362
Location: Kraków, Poland
It's just a character inside the label, it has no special meaning.
Post 02 Sep 2004, 21:12
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
it's no preprocessor, parser or assembly time operator, so it's character just like any else.
Post 03 Sep 2004, 19:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
I tried the following (changing the macro to struc)

Code:
struc union [def]
 { common size@union = 0
          origin@union = $
   forward virtual
            def
            if $-origin@union > size@union
             size@union = $-origin@union
            end if
           end virtual
   common rb size@union }

struc uretin
{
.ddHelp         dd      ?
.ddBegin        dd      ?
}

struc wimsad
{
.dwTest         dd      ?
}

struc kolp
{
.ddStart  dd      ?
.ddStop   dd      ?
.ddMode   dd      ?
.data     union     .strUretin    uretin,\
                    .strWimsad    wimsad
.lpszText dd      ?
}

k       kolp

        mov     eax,[k.strUretin]       ;This line should fail - but okay
        mov     eax,[k.data.strUretin]  ;This line should work - but fails
    


The label ".data" seems to be forgotten.

Fasm gives an error message if the union structure is put back to macro.

Any way I can solve this?
Post 13 Sep 2004, 02:39
View user's profile Send private message Visit poster's website Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
The problem is because of special meaning of dot symbol inside 'struc' statement.
The right code should be:
Code:
struc union [def]
 { common size@union = 0
          origin@union = $
   forward virtual
            .#def           ; plase dot here 
            if $-origin@union > size@union
             size@union = $-origin@union
            end if
           end virtual
   common rb size@union }


struc kolp
{
.ddStart  dd      ?
.ddStop   dd      ?
.ddMode   dd      ?
.data     union     strUretin    uretin,\ ; note: there's no dot
                    strWimsad    wimsad
.lpszText dd      ?
}     
Post 13 Sep 2004, 20:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
Aha, you got it. Thanks.
Post 14 Sep 2004, 02:15
View user's profile Send private message Visit poster's website 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-2019, Tomasz Grysztar.

Powered by rwasa.