Author Topic: pass parameter to macro  (Read 16254 times)

ilikenasm

  • Guest
pass parameter to macro
« on: February 05, 2009, 09:35:46 AM »
Hi Frank,

I wrote a macro:
%macro testmacro 1
   if %1, ==, NULL
      invoke   MessageBoxA, dword NULL, "null", 'ok', dword MB_OK
   endif
%endmacro

But got a error: invalid combination of opcode and operands
If I chage it to:
%macro testmacro 1
        mov eax, %1
   if eax, ==, NULL
      invoke   MessageBoxA, dword NULL, "null", 'ok', dword MB_OK
   endif
%endmacro

It work, why the parameter can not be compared directly?

Regards,
Freeman

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: pass parameter to macro
« Reply #1 on: February 06, 2009, 08:00:13 AM »
Not enough information. What's "NULL"? (as opposed to ' "null" '?) I suppose "if" (as opposed to "%if") and "endif" (as opposed to "%endif") are defined somewhere? If I replace "if %1, ==, NULL" with "%ifidn %1, NULL" it seems to work. Too subtle for me, I'm afraid!

Best,
Frank

nobody

  • Guest
Re: pass parameter to macro
« Reply #2 on: February 06, 2009, 09:07:17 PM »
It looks like he's using NASMX, if that's the case then I don't see why the above code wouldn't work unless you passed  an immediate value to testmacro. NASMX's if macro uses cmp internally which the arguments to if are subject to that opcodes operands. When you added the mov eax, %1 to your code you subvert your arguments dependency on a specific type of operand by forcing the first operand to cmp to be EAX.

ilikenasm

  • Guest
Re: pass parameter to macro
« Reply #3 on: February 09, 2009, 06:30:38 AM »
Yes, I'm using nasmx.
Thanks, I will use %ifidn instead.

Regards,
Freeman