Author Topic: Multi-line macros as operands  (Read 4930 times)

Offline mattsains

  • New Member
  • Posts: 1
Multi-line macros as operands
« on: March 09, 2015, 08:57:28 AM »
I wrote a small bit of assembly for nasm like this:
Code: [Select]
%macro register 1
    %if %1 = 0
        rax
    %elif %1 = 1
        rbx
    %elif %1 = 2
        rcx
    %endif
%endmacro
   
add register(1), register(2)
   
I expect that to evaluate to 'add rbx, rcx'

However, nasm -E test.asm returns this, showing that the macro is not evaluated:

Code: [Select]
%line 10+1 test.asm

add register(1), register(2)

Compare that to this code:

Code: [Select]
%macro register 1
    %if %1 = 0
        rax
    %elif %1 = 1
        rbx
    %elif %1 = 2
        rcx
    %endif
%endmacro
   
register(1)

which is transformed into

Code: [Select]
%line 10+1 test.asm

rbx

Why the difference? How can I achieve what I expect in the first snippet?