flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Try to make union example...

Author
Thread Post new topic Reply to topic
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 09 Dec 2004, 14:20
Hello, everybody!
Not so far I used MASM to write programs in assembler language, but when I found FASM, I have seen some of its advantages and now I study this assembler language. I likes it for its simplicity an because of opportunity to write everything I need by myself.
Now let me show the result of my study. I have read some useful topics of this forum and try to combine what I have read into some useful thing.
Please, don't be very critic to me.

Now, union macro:

Code:
; macro for declaring a union

macro union _name,[def] 
{ 
 common size@union = 0 
         origin@union = $ 
 forward 
  virtual 
   #_name#def 
   if $-origin@union > size@union 
    size@union = $-origin@union 
   end if 
  end virtual 
 common
 local ..array
 struc _name {
..array  rb size@union
 forward
  virtual at ..array
   def
  end virtual
 common
 uend  
}

uend fix }


;********   example of usage   **********

; declaring a union

union MYUNION,\
       .value1             dd              ?     ,\
       .value2             db              ?     ,\
       .struct1            SOMESTRUCT            ,\
       .value3             rb              100     

; defining variable

Union1 MYUNION

; acessing fields

 mov eax,[Union1.value1]
 mov al,[Union1.value2]
 mov eax,[Union1.struct1.some_struct_field]
; ... and so on

; it is possible to write in this way:

struc COMBINED
{
 .a     dd   ?
 .b     MYUNION
 .c     db   ?
}

; or to create unions of structures:

union MYUNION,\
       .value1             SOMESTRUCT1                   ,\
       .value2             SOMESTRUCT2          
    


If it isn't hard for you, please test this macro and tell me about my mistakes.

_________________
Flat Assembler is the best!
Post 09 Dec 2004, 14:20
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.