Author Topic: Deprecated feature or bug?  (Read 6982 times)

Klod

  • Guest
Deprecated feature or bug?
« on: May 29, 2012, 07:16:00 PM »
I have played around with the revamped preprocessor features and came up with the following program. It illustrates how to create a macro from within a macro. This code compiles and runs with Nasm 2.10rc2-20101123.
Code: [Select]

;Windows XP service pack 2
;\nasm\bin\NASM -f win32
;\nasm\bin\golink  @\nasm\bin\GFL.txt  /console
%warning __NASM_VER__ ;2.10rc2-20101123
%macro PROTO 2+
mac %1,%2
%endmacro

%macro mac 2-*
%push __MAC__
EXTERN %1
%assign %$ac (%0 -1)
%macro %[%1] %$ac
       %warning %? %0 ,%1
        push %1
       call %? 
%endm
%pop
%endmacro

PROTO ExitProcess,Null
PROTO scanf,ptr
PROTO printf,ptr

[Section .data]

string db 'hello',13,10,0
string2 db 'Hello again',0
string3 db 'Macros created from within a macro',0
Newline db 13,10,0
key db '%c',0

[Section .text]

Start:   
printf string
printf string2
printf Newline
printf string3
printf Newline
  scanf key

     ExitProcess 0


When compiling it with Nasm 2.10-20120507 I get the following errors:
C:\nestedMacrocall.asm:38: error: symbol `mac' undefined
C:\nestedMacrocall.asm:39: error: symbol `mac' undefined
C:\nestedMacrocall.asm:40: error: symbol `mac' undefined
C:\nestedMacrocall.asm:41: error: symbol `mac' undefined
C:\nestedMacrocall.asm:42: error: symbol `mac' undefined
C:\nestedMacrocall.asm:43: error: symbol `mac' undefined
C:\nestedMacrocall.asm:45: error: symbol `mac' undefined

The 2 macros printf  and scanf  are being created but it appears that %? refers to the name of the calling macro and not %[%1], the name of the created  macro.

\nestedMacrocall.asm:38: warning: (printf:3) macro `mac' exists, but not taking 0 parameters
\nestedMacrocall.asm:39: warning: (printf:3) macro `mac' exists, but not taking 0 parameters
\nestedMacrocall.asm:40: warning: (printf:3) macro `mac' exists, but not taking 0 parameters
\nestedMacrocall.asm:41: warning: (printf:3) macro `mac' exists, but not taking 0 parameters
\nestedMacrocall.asm:42: warning: (printf:3) macro `mac' exists, but not taking 0 parameters
\nestedMacrocall.asm:43: warning: (scanf:3) macro `mac' exists, but not taking 0 parameters
\nestedMacrocall.asm:45: warning: (ExitProcess:3) macro `mac' exists, but not taking 0 parameters


Difference between %endm and %endmacro

I have been using %endm in a lot of my macros instead of %endmacro and it always seemed to work. In the example above it throws additional errors:
\nestedMacrocall.asm:18: error: `%pop': context stack is empty
\nestedMacrocall.asm:19: error: `%endmacro': not defining a macro
\nestedMacrocall.asm:21: panic: (mac:7) defining with name in expansion

I did a wordsearch in the docs and found no preprocessor directive %endm. The only place I could find %enm was in:


Appendix C: NASM Version History (PDF)
%macro  abc     1
             %define %1 hello
     %endm

Looks like old syntax supported for compatibility?