flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > union at structure

Author
Thread Post new topic Reply to topic
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 20 Mar 2023, 07:09
Hi
Is that ok or should I use some simple directive?
Code:
struc SomeStruc
{
  .name dd ?
 virtual at .name
  .altName1    db ?
  .altName2    db ?
  .altName3    db ?
  .altName4    db ?
 end virtual
 virtual at .name
  .another1    dw ?
  .another2    dw ?
 end virtual
}
    
Post 20 Mar 2023, 07:09
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 978
Location: Russia
macomics 20 Mar 2023, 07:49
Code:
struc SomeStruc
{
  label .name dword
  label .another1 word
  .altName1 db ?
  .altName2 db ?
  label .another2 word
  .altName3 db ?
  .altName4 db ?
}    
Post 20 Mar 2023, 07:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20356
Location: In your JS exploiting you and your system
revolution 20 Mar 2023, 07:58
struc is the same as macro with the only difference that it require a label name upon instantiation.

What you post above looks perfectly fine.
Post 20 Mar 2023, 07:58
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 21 Mar 2023, 00:01
I just thinking how useful can be macro like union. How can I manage it to use predefined values. Seems I need some sort of switcher between virtual clones otherwise it is not accepted to real data
Code:
macro union autounion=0
{
        currentunion = $
        sizeofunion = autounion
        purge clone,endunion
        macro clone
        \{
                purge clone
                macro clone
                \\{
                        if $-currentunion > sizeofunion
                                sizeofunion = $-currentunion
                        end if
                        end virtual
                        virtual at currentunion
                \\}
                virtual at currentunion
        \}
        macro endunion
        \{
                if $-currentunion > sizeofunion
                        sizeofunion = $-currentunion
                end if
                end virtual
                if $-currentunion > sizeofunion
                        sizeofunion = $-currentunion
                end if
                if autounion > 0 & autounion < sizeofunion
                        display "Overflow fixed size of union.",13,10
                end if
                times sizeofunion-($-currentunion) db ?
        \}
}    

Code:
struc SomeStruc Lab=0,Param=0,Matrix=0
{       
        .adr                    dq Lab
        .param                  dd Param
                                dd ?
                union 32
        .matrix                 dd Matrix
                clone
        .point1.X               dd ?
        .point1.Y               dd ?
        .point2.X               dd ?
        .point2.Y               dd ?
                clone
        .mesh                   db 24 dup(?)
                endunion
}    
Post 21 Mar 2023, 00:01
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.