flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > macro local labels

Author
Thread Post new topic Reply to topic
pjd



Joined: 15 Jul 2007
Posts: 47
pjd 17 Jul 2007, 10:32
how do I create labels local to the macro in which they are defined so that it can have a list of local variables connected to it (with a dot) within the macro that do not interfere with labels local to a global variable outside the macro?
Post 17 Jul 2007, 10:32
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Jul 2007, 10:43
[moved this to Macroinstructions]

you mean something like this?
Code:
macro pushstr string
{
  local x, y   ;<-- here
  push y
  jmp x
  y db string
  x:
}
pushstr 'xyz'
pushstr 'abcd'
    
Post 17 Jul 2007, 10:43
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
pjd



Joined: 15 Jul 2007
Posts: 47
pjd 17 Jul 2007, 11:10
That doesn't seem to work
this is the code
Code:
    if_arguments:
   cmp edi, 0      ;are there any more arguments?
      je noarguments  ;if not jump down
   .yesarguments:
          pop ecx ;pop the argument
           dec edi ;and say an argument is gone
                string_length eax
           mov edx, eax
                sys_write fd_console_out, ecx, edx
          put_char fd_console_out, 10
         jmp .end
    .noarguments:
   
    .end:
    


and the called macro

Code:
    macro string_length string
  {
              mov eax, string
             lenloop:
                        cmp byte [eax], 0
                   je .end
                             inc eax
                     jmp lenloop
         .end:
           sub eax, string
     }
    


the .end in the code seems to think it follows from the lenloop in the macro instead of the if_arguments outside the macro

p.s. thanks for moving the thread to the right place
Post 17 Jul 2007, 11:10
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Jul 2007, 15:52
first of all, you shouldn't do this with macro, you should use procedure instead.

Do you understand what happens after preprocessor is done expanding macros? Your line "string_length eax" becomes:
Code:
                mov eax, eax
                lenloop: 
                        cmp byte [eax], 0 
                        je .end 
                                inc eax 
                        jmp lenloop 
                .end: 
                sub eax, eax  ;<- uh-oh
    


i suggest you to use procedure instead.



PS: you shouldn't name your macro ".end" if you are using windows includes (win32ax.inc). I suppose you aren't, but just for sure...
Post 17 Jul 2007, 15:52
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
pjd



Joined: 15 Jul 2007
Posts: 47
pjd 17 Jul 2007, 18:45
the macro should have been given ecx not eax to work on. Thanks for spotting the bug.

I've been using NASM up till now and I am looking at whether FASM is better or not.
In NASM I can define macros with labels like
Code:
%macro foo 0
;code (can reference %%label)
%%label:
;more code (can reference %%label)
%end macro

foo
;can't see %%label here
    

because the label begins with %% it is macro local label and the %% gets exchanged for ..@ and a number. can I do that under FASM? (adding local lines in the macro doesn't work) I don't want to use procedure (with enter/leave) as it fiddles with the stack.
Post 17 Jul 2007, 18:45
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 17 Jul 2007, 19:00
Code:
macro foo
{
local ..label
..label:
}

foo
;Can't see ..label (unless you guess the UID in which case you can replace the Xs in ..local?XXXXXXXX with every digit of that number) here and it does not affect current scope since it starts with two dots.    


Quote:
(adding local lines in the macro doesn't work)

Why not?
Post 17 Jul 2007, 19:00
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Jul 2007, 21:17
I splitted posts about FASM vs. NASM here
Post 17 Jul 2007, 21:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
pjd



Joined: 15 Jul 2007
Posts: 47
pjd 18 Jul 2007, 09:04
LocoDelAssembly wrote:
Code:
macro foo
{
local ..label
..label:
}

foo
;Can't see ..label (unless you guess the UID in which case you can replace the Xs in ..local?XXXXXXXX with every digit of that number) here and it does not affect current scope since it starts with two dots.    


Quote:
(adding local lines in the macro doesn't work)

Why not?


silly me you need
Code:
local ..label    
not
Code:
local label
;messes with .external_labels    

Thanks for showing me common sense
Post 18 Jul 2007, 09:04
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.