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:
; 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.