flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macro for conditional mov

Author
Thread Post new topic Reply to topic
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 04 Apr 2010, 23:03
Code:
irps cond, a b e z na nb ne nz
{
   macro mov#cond dst*,src*,else_src
   {
      if cond eq
         mov dst,src
      else
         local cond_unmet
         local cond_met
         j#cond cond_met
         jmp cond_unmet
         cond_met:
         mov dst,src
         cond_unmet:
         if ~(else_src eq )
            display `else_src
            mov dst,else_src
         end if
      end if
   }
   if defined `mov#`cond
      display `mov#`cond
   end if
}  
    

It doesn't display any messages, so apparently the macros aren't being defined. Anyone know how to fix it?


Last edited by Tyler on 11 Apr 2010, 21:08; edited 1 time in total
Post 04 Apr 2010, 23:03
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 04 Apr 2010, 23:14
Never mind, stupid mistake, I forgot the "\"s in front of the nested brackets. It works now. I hope someone else can get some use out of this too Smile.
Code:
irps cond, a b e z na nb ne nz
{
   macro mov#cond dst*,src*,else_src
   \{
      if cond eq
         mov dst,src
      else
         local cond_unmet
         local cond_met
         j#cond cond_met
         jmp cond_unmet
         cond_met:
         mov dst,src
         cond_unmet:
         if ~(else_src eq )
            display `else_src
            mov dst,else_src
         end if
      end if
   \}
   if defined `mov#`cond
      display `mov#`cond
   end if
}
    
Post 04 Apr 2010, 23:14
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 05 Apr 2010, 01:19
Fixes for some mistakes I didn't notice.
Code:
irps cond, a b e z na nb ne nz
{
   macro mov#cond dst*,src*,else_src
   \{
      if cond eq
         mov dst,src
      else
         j#cond .cond_met
         if ~(else_src eq )
            mov dst,else_src
         end if
         jmp .cond_unmet
         .cond_met:
         mov dst,src
         .cond_unmet:
      end if
   \}
}
    
Post 05 Apr 2010, 01:19
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 09 Apr 2010, 20:02
Tyler,

Some remarks:

1. «if cond eq» will always take «else» branch.
2. Do you really need extra unconditional jump in case else_src is empty?
3. Labels .cond_met & .cond_unmet are not macro-local.
4. While cmovcc instructions are restricted to "r/m -> reg" kind of mov, they support full range of condition code mnemonics.
Post 09 Apr 2010, 20:02
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 09 Apr 2010, 21:37
An updated version with local labels and a conditional call macro. http://board.flatassembler.net/topic.php?t=11375&start=2
Post 09 Apr 2010, 21:37
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.