flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Modify exist macros

Author
Thread Post new topic Reply to topic
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
Is it possible to add some extra lines to exist macro?
Code:
macro used_macro Params&
        {       
        macro Params
        ;stick somehow xor eax,eax 
        }       
macro fix used_macro

macro test  { }

test   ;to get result as xor eax,eax
    
Post 25 Aug 2020, 16:39
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
Seems it works. But what if } in the line of some commands? Can I force it to next line?
Code:
macro used_macro Params&
        {    
        \} fix xor eax,eax \}
        macro Params
        }       
macro fix used_macro    

Is that fix located for next line macro Params only? Can I localisate it somehow? Or maybe exist some other solution?
Post 25 Aug 2020, 16:52
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 807
Location: Belarus
DimonSoft
Just define a new macro and call the original one from it. The only problem is to get the macro name without parameters but I’ve shown the trick in the original suggestion.
Post 25 Aug 2020, 17:35
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
Read remark there.
Post 25 Aug 2020, 17:45
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
Do you mean like this? Then I have to declare default macro body in bottom -- it's a problem as I have to redefine it with correct name and params
Code:
macro ifused_macro Params&
        {       
        macro Params
        ; seems macro Params needs to be in the end
        
        ifused_macro_Param      equ Params \# !
        ifused_macro_clear      equ Params
        match name rest, ifused_macro_Param 
                \{
                macro ifused_macro_clear
                        \\{
                        name rest
                        ; some extra operator here...
                        \\}
                \}
        }       
macro fix ifused_macro    
Post 25 Aug 2020, 18:23
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 807
Location: Belarus
DimonSoft
Ah, now I see your problem: you want to add something to the macro you’re defining while doing previously discussed bookkeeping.

The easiest solution I can see is to trick the one who defines macro. Something along the lines of:
Code:
macro ifused_macro Params&
{
  ; Bookkeeping goes here or wherever you wish

  local realimpl, def

  match name rest , Params !
  \{
    macro name p&
    \\{
      ; Do anything
      realimpl p
      ; Do more of anything
    \\}
  \}

  match name any , Params
  \{
    def equ macro realimpl any
    rept 0 \\{
  \}
  match ,
  \{
    def equ macro realimpl
  \}

  def
}

macro fix ifused_macro    
Post 26 Aug 2020, 09:34
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
I fixed your macro but it still not working. Read comments.
Code:
macro ifused_macro Params&
        {
        local realimpl, def, clear_string
        clear_string equ Params         ; it cuts off extra data
        match name rest,clear_string !     ; '!' adds pseudo argument
                \{
                macro name [p]              ; fixed
                        \\{
                        ; Do anything
                        realimpl p
                        ; Do more of anything
                        \\}
                \}
        ; 'match' need to be once as 'any' contain extra data any way
        match name any,Params  
                \{
                macro realimpl any     ;I cannot use 'equ' as it cuts off extra data
                \}
        }
macro fix ifused_macro    
Post 26 Aug 2020, 12:42
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 807
Location: Belarus
DimonSoft
I didn’t really try the code I gave in my previous post, just wrote it in browser to show the idea: use the name specified to define your own macro which does anything you wish and calls the real macro. The real macro now has to have another name, which can be generated with local.

Note also that your asssumption that any always contains something is wrong. What if I define a macro like this?
Code:
macro align_to_sector
{
  db 512 - ($ - $$) mod 512 dup(0)
}    
Post 26 Aug 2020, 13:26
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
It contains next strings as you made it by Params&. As I understand this...
I shown you example where it works with any kind of macros and { in other thread. Check that example.
Post 26 Aug 2020, 15:35
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
Any more ideas? Don't let it die...
Post 06 Sep 2020, 23:38
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.