flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How two macros linking ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1807
Roman 13 Jun 2023, 10:53
Fasmw 1.73
Code:
macro lm_ a,b=0 {
      if b = 0
         macro lmb \{ inc a \}
      end if
     if b > 0
         macro lmb \{ dec a \}
      end if
      }
;in code
            lm_ eax
            lmb
            lm_ eax,1
            lmb
            lm_ eax
            lmb 
    

I get all dec eax, but way ?
I expected get:
inc eax
dec eax
inc eax

I changed macro but result the same(all dec eax) !
Code:
macro lm_ a,b=0 {      
         match e,b \{
         ;display e+48
         if e = 0
         display '0;;'
         macro lmb \\{ inc a \\}
         end if
         if e > 0
         display '1;;'
         macro lmb \\{ dec a \\}
         end if
         \}    
      }
    
Post 13 Jun 2023, 10:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20357
Location: In your JS exploiting you and your system
revolution 13 Jun 2023, 12:58
You have the same problem of mixing the assembler and preprocessor. You can't conditionally define a macro within an if block. The macro is always defined.

So to fix it you need to use the preprocessor to conditionally define macros.
Code:
match =0, b {
 macro lmb \{
  ;...
 \}
}match =1, b {
 macro lmb \{
  ;...
 \}
}    
Post 13 Jun 2023, 12:58
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1807
Roman 15 Jun 2023, 08:51
Code:
macro lm2 a,b=0 {
match =0, b \{
 macro lmb \\{ Inc a
  purge lmb ;in this place not working
 \\}
\}
} 
;in code
lm2 eax
lm2 ecx
lmb  ;I get Inc ecx 
lmb ;I get Inc ecx, but must be  Inc eax

;this OK
lm2 eax
lm2 ecx
lmb  ;I get Inc ecx 
purge lmb
lmb ;I get  Inc eax
    
Post 15 Jun 2023, 08:51
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20357
Location: In your JS exploiting you and your system
revolution 15 Jun 2023, 08:58
A macro cannot purge itself.

Purge does work inside a macro, but it will purge a previous definition, not itself.
Post 15 Jun 2023, 08:58
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 15 Jun 2023, 13:56
Roman, I tryed to reproduce thour problem and I couldn`t - not found a problem at all:
Code:
use32
incdec0 equ inc
incdec1 equ dec
macro lm_ a,b=0 { define lmb incdec#b a }

macro lmb { match a,lmb \{ a \}
        restore lmb }

lm_ ecx
lm_ eax,1
lmb
lmb      

next one lmb will throw error
Code:
use32
incdec0 equ inc
incdec1 equ dec
macro lm_ a,b=0 { define lmb Roman' incdec#b a }

macro lmb { match =Roman' a,lmb \{ ; check for Roman' in definition
        a
        restore lmb \} }

lm_ ecx
lm_ eax,1
lmb
lmb
lmb ; no error here it just does nothing    

or this way
Code:
use32
incdec0 equ inc
incdec1 equ dec
macro lm_ a,b=0 { define lmb incdec#b a }

macro lmb {
        irpv any,lmb \{ ; check if defined at least once
                common 
                match a,lmb \\{ a \\}
                restore lmb \} }

lm_ ecx
lm_ eax,1
lmb
lmb
lmb    
Post 15 Jun 2023, 13:56
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1807
Roman 15 Jun 2023, 16:24
ProMiNick you do trick and restore one equ value, but not hole macro.
My example simple, but sometimes macro have 20 asm commands or more.
For this reason I asked about purge.
Post 15 Jun 2023, 16:24
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 15 Jun 2023, 16:51
linking of symbols(macronames or whatever) is always via define or equ.
just imagine thou create set of macros with temporary names (or even local names of some macro, so that names would be unnaccesible outside of that outer macro) and link that names to some symbol with help of equ or define.
Than thou could unwind all values of link symbol that are macros by nature.
Post 15 Jun 2023, 16:51
View user's profile Send private message Send e-mail 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.