flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > union macro

Author
Thread Post new topic Reply to topic
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica
I've been doing some work with structures latley and I've been using unions rather much, writing "virtual at .foo/.../end virtual" is getting booring so I decided to make a macro to ease my work:
Code:
macro union _at, [_item, _type] {
  common
    virtual at _at
  forward
    _item _type ?
  common
    end virtual
}
; use like this:
;struc test{
;  .FooBar dd ?
;  union .FooBar, .Foo,dw, .Bar,dw
;}
; or like this ( "same but different" Wink
;struc test{
;  .FooBar dd ?
;  union .FooBar,\
;        .Foo,dw,\
;        .Bar,dw
;}
; the members are acceses as if they're any other member, thus:
; mov [teststruct.FooBar], dword 0
; mov [teststruct.Foo], word -1
    

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn


Last edited by scientica on 05 Jul 2003, 13:43; edited 1 time in total
Post 05 Jul 2003, 13:26
View user's profile Send private message Visit poster's website Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica
Idea I just realised above can't do structures, so I had to rewrite it a little:
Code:
macro union _at, [_item, _type] {
  common
    virtual at _at
  forward
    _item _type
  common
    end virtual
}

example of usage:

 struc WOHO{
 .d dd ?
 .b dd ?
}
struc FTX{
  .ddMasterTimeUnit dd ?
  union .ddMasterTimeUnit,\
         .dwYear,dw ?,\
         .dbMonth,db ?,\
         .dbDay,db ?,\
         .Test, WOHO
}

section '.data' data readable writeable
        stest FTX

section '.code' code readable executable
  start:
        mov   [stest.dbMonth], 1
        mov   [stest.Test.b],-1    

Note with this verison you must specify "dd ?" instead of "dd", but now you can unify structures too.

_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 05 Jul 2003, 13:41
View user's profile Send private message Visit poster's website Reply with quote
BiDark



Joined: 22 Jun 2003
Posts: 110
Location: .th
BiDark
My version (in the past).

Code:
union equ UNION
macro union main,[name]
{
common
  local _label
  _label:
    main
forward
  virtual at _label
    name
  end virtual
}

struc TVITEM
{
  .mask              dd ?
  .hItem             dd ?
  .state             dd ?
  .stateMask         dd ?
  .pszText           dd ?
  .cchTextMax        dd ?
  .iImage            dd ?
  .iSelectedImage    dd ?
  .cChildren         dd ?
  .lParam            dd ?
}

struc TVITEMEX
{
  .mask              dd ?
  .hItem             dd ?
  .state             dd ?
  .stateMask         dd ?
  .pszText           dd ?
  .cchTextMax        dd ?
  .iImage            dd ?
  .iSelectedImage    dd ?
  .cChildren         dd ?
  .lParam            dd ?
  .iIntegral         dd ?
}

struc ITEMTYPE
{
  union <.itemex TVITEMEX>,\ ; put the largest member first
          <.item TVITEM>
}
    
Post 06 Jul 2003, 03:52
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-2019, Tomasz Grysztar.

Powered by rwasa.