flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Is it possible to overload an ASM instruction with macro?

Author
Thread Post new topic Reply to topic
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 14 Nov 2010, 12:46
Hello,

Is it possible for example to overload the "MOV" instruction with a macro to accept something like the following:

Code:
mov  [var_1], [var_2]    


which internally it could generate something like:

Code:
mov   eax, [var_2]
mov   [var_1], eax    


I was just wondering.... Smile

Thanks!
Post 14 Nov 2010, 12:46
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8363
Location: Kraków, Poland
Tomasz Grysztar 14 Nov 2010, 13:17
Have you checked the fasm's manual? It contains this example:
Code:
    macro mov op1,op2
     {
      if op1 in <ds,es,fs,gs,ss> & op2 in <cs,ds,es,fs,gs,ss>
        push  op2
        pop   op1
      else
        mov   op1,op2
      end if
     }    
It can be easily modified into something with memory-to-memory capability, like:
Code:
    macro mov op1,op2
     {
      if op1 eqtype [var] & op2 eqtype [var]
        push  op2
        pop   op1
      else
        mov   op1,op2
      end if
     }    


Just note that macroinstructions are case-sensitive, while instructions are not. So when you redefine "mov" as macro, "MOV" is still going to be just regular instruction.
Post 14 Nov 2010, 13:17
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 14 Nov 2010, 22:35
Thanks a lot Tomasz!!!
Post 14 Nov 2010, 22:35
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.