flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Macro repeat problem!

Author
Thread Post new topic Reply to topic
u111no



Joined: 27 Apr 2007
Posts: 2
Location: Moscow
u111no 27 Apr 2007, 09:03
Hellow!
I'v got a problem with macro write.
To use macro in some programs, I'v made an *.inc file with macro.
Here the cod of the *.inc file with macro (MyMacro.inc):
Code:
   
; The macro multiply M1 to M2 by using the loop cycle

    macro  ProMul M1,M2
   {
    mov dx,0
    mov cx,M1
   Lmul:
   add dx,M2
   Loop Lmul
   }
    

Here the cod of some short program, that uses my macro:
Code:
   
   include      'MyMacro.inc'
   org    100h
   mov    ah,02h
   ; First ask of my Macro
   ProMul  2,3 ; It's working.
   add     dl,30h
   int     21h
   ; Second ask of my Macro
   ProMul  3,3  ; Error: Symbol already defined -> Lmul
   add     dl,30h
   int     21h
   ; Stop of the program to see the screen
   mov    ah,0h
   int    16h
   ; Out from program
   int    20h
     

What should I do to make my macro work with Loops (Jumps) more then once in program?
Thanks for your replies.
Post 27 Apr 2007, 09:03
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 27 Apr 2007, 09:39
Code:
 macro  ProMul M1,M2 
   { 
        local ..Lmul   ;<---
        mov dx,0 
        mov cx,M1 
        ..Lmul:        ;<----
        add dx,M2 
        Loop Lmul 
   }    


prefixing macro-local name with two dots is good idea, so that it doesn't change current "namespace" label
Post 27 Apr 2007, 09:39
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
u111no



Joined: 27 Apr 2007
Posts: 2
Location: Moscow
u111no 27 Apr 2007, 09:53
Thank you Vid.
All works!!

P.S. [Loop Lmul] -> [Loop ..Lmul] too
Post 27 Apr 2007, 09:53
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 27 Apr 2007, 09:57
Quote:
Thank you Vid

you're welcome.

by the way, it's "vid", not "Vid" Wink
Post 27 Apr 2007, 09:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan 27 Apr 2007, 14:57
Let me ask this question, what the reason to write
Code:
local ..Lmul    
and not
Code:
local .Lmul    
. ..Lmul will have global scope being local label if 2 dots but what for 2 not one?

_________________
Any offers?
Post 27 Apr 2007, 14:57
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 28 Apr 2007, 15:17
there is no resulting difference whether you use two dots or just one, because "local" directive changes the resulting name.

Using two is better for clarity, local labels should be used only for local things
Post 28 Apr 2007, 15:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 28 Apr 2007, 15:36
In this scenario (among others), double dotted labels are needed:

Code:
macro block{
local ..end

  macro exit\{jmp ..end\}
  macro end\{..end:\}
} 

block 
  ; some code
  exit ; Works since aLabel doesn't hide double dotted labels
aLabel:
  ; some code
end    
Post 28 Apr 2007, 15:36
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.