flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Union for macros.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1775
Roman 31 Dec 2023, 03:54
Fasmw 1.73
Lets say I have three macros.
Code:
macro a1 v { local .1
Cmp [v], 0
Jz .1
Some code
.1:
}

macro b1 v { local .1
Cmp [v], 0
Jz .1
Some code
.1:
}

macro c1 v { local .1
Cmp [v], 0
Jz .1
Some code
.1:
}

    


If I write:
a1 v1
b1 v1
c1 v1

I want do one Cmp [v1], 0 and jz .1
Not three.


Last edited by Roman on 31 Dec 2023, 09:38; edited 2 times in total
Post 31 Dec 2023, 03:54
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1775
Roman 31 Dec 2023, 05:19
Code:
macro a1 v,f=0 { local .1
      if f = 0
      cmp dword [v],0
      jz  .1
      end if
      inc v
.1:
      }
macro b1 v,f=0 { local .1
      if f = 0
      cmp dword [v],0
      jz  .1
      end if
      add v,2
.1:
      }
macro c1 v,f=0 { local .1
      if f = 0
      cmp dword [v],0
      jz  .1
      end if
      dec v
.1:
      }
macro aa v,mtk {
      cmp v,0
      jz  mtk
      }
macro munion a,v,[b] {
      common
      local .1
      a v,.1
      forward
      b  v,1
      common
.1:
      }
val1 dd 0
Start:   
          mov eax,val1
          a1 eax
          b1 eax
          c1 eax
          munion aa,byte [eax],a1,b1,c1
          munion aa,dword [eax],a1,b1,c1
          munion aa,eax,a1,b1,c1
    
Post 31 Dec 2023, 05:19
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 31 Dec 2023, 08:27
Classic union means different data, names or types for the same location for different scenarios of use. So why you call your macro as union? Anyway, you want your macro to insert some group of instructions but avoid cmp then remove it or turn it off as you started to do by if IF instruction. Or do some like this
Code:
 
macro conveyor operand, [car] 
{
cmp [operand], 0
je  @F
forward
car operand
common
@@:
} 
    
Post 31 Dec 2023, 08:27
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 934
Location: Russia
macomics 31 Dec 2023, 10:41
Why be so tricky. Just put the shared code in a separate macro and use it as a union.
Code:
macro a1@body v { inc v }
macro a1 v,f=0 { local .1
      if f = 0
      cmp dword [v],0
      jz  .1
      end if
      a1@body v
.1:
      }
macro b1@body v { add v, 2 }
macro b1 v,f=0 { local .1
      if f = 0
      cmp dword [v],0
      jz  .1
      end if
      b1@body v
.1:
      }
macro c1@body v {dec v }
macro c1 v,f=0 { local .1
      if f = 0
      cmp dword [v],0
      jz  .1
      end if
      c1@body v
.1:
      }
macro aa v,mtk {
      cmp v,0
      jz  mtk
      }
macro munion a,v,[b] {
      common
      local .1
      a v,.1
      forward
      b  v,1
      common
.1:
      }
val1 dd 0
Start:   
          mov eax,val1
          a1 eax
          b1 eax
          c1 eax
          munion aa,byte [eax],a1@body,b1@body,c1@body
          munion aa,dword [eax],a1@body,b1@body,c1@body
          munion aa,eax,a1@body,b1@body,c1@body    
Post 31 Dec 2023, 10:41
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.