flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Flag in macros. Help to solve.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1823
Roman 17 Sep 2013, 19:21
My macro:
Quote:

DoProc = 0
macro Loo x{ local Pr0
if DoProc = 0
jmp Pr0
Pr1:
invoke MessageBox,0,eax,0,0
ret
Pr0:
DoProc = 1
end if
mov eax,x
Call Pr1
}




If i not write DoProc = 0 my macro not work. Fasm swears on DoProc in macro.
How fix this. I want use my macro but do not explicitly specify DoProc.
Because I will have a lot of similar macros. And write for each macro flag (like DoProc ) somehow not healthy and not cool.
Post 17 Sep 2013, 19:21
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 17 Sep 2013, 21:46
Roman,

Do you want to check whether Loo macroinstruction is invoked first time? It can be done several ways:
Code:
; Using symbolic constant
macro Loo x {
  match =_Loo, _Loo \{
  ; seems that '_Loo' is undefined, let's do it
  \local ..Loo, ..Loo0
        jmp     ..Loo0
..Loo:  invoke  MessageBox, 0, eax, 0, 0
        ret
..Loo0:
    _Loo equ ..Loo; now it's defined
  \}
        mov     eax, x
        call    _Loo; here '_Loo' is defined properly in any case
}


; Using numeric constant
macro Loo x {
local ..Loo, ..Loo0
  if ~defined _Loo
        jmp     ..Loo0
..Loo:  invoke  MessageBox, 0, eax, 0, 0
        ret
..Loo0:
    _Loo = ..Loo
  end if
  _Loo = _Loo; make it out of scope above
        mov     eax, x
        call    _Loo
}    
They're quite similar: symbolic one is straightforward, numeric uses defined operator to check if _Loo constant is defined before (because redefinition makes it inaccessible from above).

Do you think you'll get twice as much help if you post this in two forums? Then why not in three (or all at once)? And please use [code]…[/code] tags.
Post 17 Sep 2013, 21:46
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.