home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 3,702 of 4,675   
   James Harris to All   
   Nasm macros and labels   
   22 Dec 18 21:19:50   
   
   From: james.harris.1@nospicedham.gmail.com   
      
   Any of you guys up to speed with Nasm macros and how labels work with   
   them? Something I am trying to do makes sense to me but even with   
   multiple variants it is not working.   
      
   The idea is to define macros to help with string literal inclusion in   
   source code (as mentioned as an option in a recent thread).   
      
   In code, writing   
      
        lit "Hello", 10, 0   
      
   is supposed to expand to   
      
      [section .data]   
      string_literal_1: db "Hello", 10, 0   
      __SECT__   
      
   That bit seems to work. But then   
      
        mov eax, cons   
      
   is meant to expand to   
      
        mov eax, string_literal_1   
      
   where the "1" matches this label with the above. But it doesn't work.   
      
   Here's a simplified pair of macros. The "lit" macro ensures there is a   
   symbol N and defines a label as follows.   
      
      %macro lit 1+ ;.nolist   
      
      %ifndef N   
      %assign N 0   
      %endif   
      
      %assign N N + 1   
      
      [section .data]   
      string_literal_%[N]: db %1   
      __SECT__   
      
      %endmacro   
      
   The "cons" macro is supposed to access the latest value of N and is   
   defined as follows.   
      
      %define cons (string_literal_%[N])   
      
   Unfortunately, when I try to assemble code I get told the following   
      
      nasm -f elf -o c0.o c0.nasm -l c0.nasm.list   
      c0.nasm:184: error: symbol `string_literal_N' undefined   
      
   It's as if the second macro doesn't see the N defined in the first and   
   so leaves it as, literally, "N".   
      
   Maybe I misunderstand how Nasm uses labels in macros, or I've been   
   looking at it too long and I'm missing something which should be   
   obvious. Can anyone see what's wrong?   
      
      
   --   
   James Harris   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca