flat assembler
Message board for the users of flat assembler.

Index > Main > several structs how do?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 22 Dec 2022, 07:16
fasmw 1.73
Code:
struct a
a1 dd 0
ends

struct b
b1 db 0
ends

struct c
c1 db 0
ends

Hero a, b      ;fasm error
Hero2 c,b,a    ;fasm error
;in code
Mov [Hero.b1],1 ;fasm error
    
Post 22 Dec 2022, 07:16
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 22 Dec 2022, 09:10
My variant:
Code:
;data
Hero    a
        b
        c

virtual at ecx
        s a
        e b
        d c
end virtual
                mov ecx,Hero
                mov [s.life],1
                mov [e.b1],1
                mov [d.c1],1 
    
Post 22 Dec 2022, 09:10
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 22 Dec 2022, 09:26
Perhaps this would suffice?
Code:
struct abc
  union
    struct
      a1 dd 0
    ends
    struct
      b1 db 0
    ends
    struct
      c1 db 0
    ends
  ends
ends

Hero abc

mov [Hero.b1],1
mov eax,[Hero.a1]    
Or, if you only need single fields and not whole structures, even simpler:
Code:
struct abc
  union
    a1 dd 0
    b1 db 0
    c1 db 0
  ends
ends    
But there is also a trick to do exactly what you asked for:
Code:
struc unionof names&
{
  .: macro label def \{ \}
  local size
  size = 0
  irp name, names
  \{
    virtual at .
      . name
      if $-. > size
        size = $-.
      end if
    end virtual
  \}
  rb size
  purge label
}


struct a
a1 dd 0
ends

struct b
b1 db 0
ends

struct c
c1 db 0
ends

Hero unionof a, b
Hero2 unionof c,b,a    
Post 22 Dec 2022, 09:26
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 22 Dec 2022, 09:39
Quote:

Hero unionof a, b
Hero2 unionof c,b,a

Yes. This is I want !
Thanks.

For unionof not work times 5\repeat\rept 1000 { unionof c,b,a }

Code:
struc unionof num,names&
{
  .: macro label def \{ \}
  local size
  size = 0
  irp name, names
  \{
    virtual at .
      . name
      if $-. > size
        size = $-.
      end if
    end virtual
  \}
  rb size*num
  purge label
}

Hero unionof 8,a, b
    
Post 22 Dec 2022, 09:39
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.