flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > In macro match not see label from other match.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1792
Roman 13 Apr 2023, 10:28
Fasmw 1.73
Code:
Macro a { local .l1
match \{.l1: 
Lbb equ .l1
\}

match \{jnz .l1 ;fasm error undefined .l1
jnz Lbb ;this variant work and compiled fine
 \}
}
    
Post 13 Apr 2023, 10:28
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 949
Location: Russia
macomics 13 Apr 2023, 10:30
So the first match didn't work and .l1 is not declared.

Here I have the same thing working fine.
Code:
macro   .idata  [libs]
{   common      purge .idata
    macro .idata args& \{ err \}
    section '.idata' import data readable writeable
      import.data:
    forward libs#.spec:if defined libs#.value
                dd RVA libs#.look, 0, 0, RVA libs#.value, RVA libs#.addr
      end if
    common if $ > import.data
                dd 5 dup (0)
      end if
}

macro   import  lib,[fnc]
{   common      rb (- RVA $) and 7
      match name==from, lib \{ if defined name\#.spec
          name\#.look:
      \}
    forward     local .text
        match name==from, lib \{ match proc==text, fnc \\{
        if used proc
          label proc qword at name\\#_\\#proc
        end if
        if used name\\#_\\#proc
          if text eqtype ''
                dq RVA .text
          else
                dq 0x8000000000000000 + text
          end if
        end if
      \\} \}
    common      match name==from, lib \{ if $ > name\#.look
                dq 0
        end if
        name\#.addr:
      \}
    forward     match name==from, lib \{ match proc==text, fnc \\{
        if used name\\#_\\#proc
          if text eqtype ''
            name\\#_\\#proc dq .text
          else
            name\\#_\\#proc dq 0x8000000000000000 + text
          end if
        end if
      \\} \}
    common      match name==from, lib \{ if $ > name\#.addr
                dq 0
          name\#.value db from, 0
                rb RVA $ and 1
        end if
      \}
    forward     match name==from, lib \{ match proc==text, fnc \\{
        if used name\\#_\\#proc & text eqtype ''
          .text dw 0
                db text, 0
                rb RVA $ and 1
        end if
      \\} \}
    common      match name==from, lib \{ end if \}
}

.idata kernel32.dll = "kernel32.dll"
import kernel32.dll,\
       ExitProcess = "ExitProcess"    


Last edited by macomics on 13 Apr 2023, 10:35; edited 3 times in total
Post 13 Apr 2023, 10:30
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1792
Roman 13 Apr 2023, 10:31
I write simple example. For focus on main problem.
In my code work both match, but second match not see label from first match.

Maybe(this is problem) in my case first run second match, then run first match.
Post 13 Apr 2023, 10:31
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 949
Location: Russia
macomics 13 Apr 2023, 10:41
Do you happen to have no global label declaration between the first and second match?

Code:
Macro a { local .l1
match \{.l1: 
Lbb equ .l1
\}
global_label: ; <<< ?
match \{jnz .l1 ;fasm error undefined .l1
jnz Lbb ;this variant work and compiled fine
 \}
}    
Post 13 Apr 2023, 10:41
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1792
Roman 13 Apr 2023, 10:46
Code:
macro flex22 a,[p] { local .up ;this is problem error
      common
      fl_oo equ 0
      cnt = 0
      define _a2  a
      forward
match =for d, p \{ ;local .up
      xor ecx,ecx
   .up:  ;fl_eqlb equ .up
      display 'for',13,10
      define _a2  a+ecx      
      cnt = d      \}

match =mout d, p \{
           inc ecx
           cmp ecx,cnt
           jb .up  ;fasm error undefined .up?Sg

      \}   }
flex22  eax,for 20,mout ptxt  ;ptxt db 0,0,0,0,0,0,0,0,0
    

This compiled OK !
Code:
macro flex22 a,[p] { 
      common
      fl_oo equ 0
      cnt = 0
      define _a2  a
local .up
      forward
match =for d, p \{ ;local .up
      xor ecx,ecx
   .up:  ;fl_eqlb equ .up
      display 'for',13,10
      define _a2  a+ecx      
      cnt = d      \}

match =mout d, p \{
           inc ecx
           cmp ecx,cnt
           jb .up  ;fasm error undefined .up?Sg

      \}   }
flex22  eax,for 20,mout ptxt  ;ptxt db 0,0,0,0,0,0,0,0,0
    
Post 13 Apr 2023, 10:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20337
Location: In your JS exploiting you and your system
revolution 13 Apr 2023, 10:58
Code:
macro flex22 a,[p] { local .up
      common
;...}    
All macros start in "forward" mode, so "local .up" is in a forward block.

It is the same as:
Code:
macro flex22 a,[p] {
      forward
       local .up
      common
;...}    
Post 13 Apr 2023, 10:58
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1792
Roman 13 Apr 2023, 11:02
Now I understand my error completely.
Post 13 Apr 2023, 11:02
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.