Author Topic: Preprocessor  (Read 8534 times)

nobody

  • Guest
Preprocessor
« on: February 13, 2008, 03:56:21 AM »
Is it possible to redirect nasms out put to a file if used :
..\..\bin\nasm  -e %file%.asm -->mac.err ????
I' trying to make use of Nasms preprocessor. This macro does not behave as I expected..
I would like to check what kind of argument I'm passing to the macro

%define string db 'blablah,0
%define val dd 1234
%macro param 1-*
%rep %0
%ifstr %1
   %error %1 'is string'
   %endif
%ifid %1
   %error %1 'is a label'
   %endif
%ifnum %1
   %error %1  'is a number'
   %endif
%else         ;this is an error
%error 'empty arg'

%endif
%rotate 1
%endrep
%endmacro

and calling it like:
param Function,'abcd',"efgh",,3,val,dword string

The Output is:
warning: Function  'is a label'         ;no label Function defined???
error: abcd               ;true
error: efgh               ;true
error: 'empty arg'            ;true
warning: 3  'is a number'         ;true
warning: dword db blahblah  'is a label'   ;label is string ?????

could someone help me with this?
Your help is appreeciated

nobody

  • Guest
Re: Preprocessor
« Reply #1 on: February 13, 2008, 09:55:25 AM »
Ahhh... I'm not good on macros...

As posted, you've got a missing "'" in string, and a mismatched else... Fixing those, it seems to act more-or-less as expected. Don't expect too much - %ifnum, for example, doesn't recognize "-1" as a number (use "0-1", if you need it).

You should be able to get preprocess-only output from "-e" - weirdly, the errors go to stderr, the rest to stdout, so you may need to do it twice to see it all. I'm not sure it'll help.

It *might* help figure out what's going on if you use something like "mov eax, 'str'"/"mov eax, 'id'"... instead of the "%error" mechanism...

Best,
Frank

nobody

  • Guest
Re: Preprocessor
« Reply #2 on: February 14, 2008, 03:55:52 AM »
Thanks Frank  for your reply
"Ahhh... I'm not good on macros... ", neither am I

I copied my code rather hastely, so ... typos. As for the else statement, I placed it there to better illustrate what I intended to do. I would like to create a sizeof macro that would give me the size of a passed argument.

I have no problem to compile with the -e option. I also see all the out put on stdout. the reason to send out put to a file was so I could copy the out put and paste it in my post rather tha having to retype it all, just convenience.
What throws me is:
warning: Function 'is a label' ;no label Function defined???
error: abcd ;true
Why the difference of out put, warning: vs error:

Thanks for the suggestion mov eax, 'str'. I will play around with this.

Thanks in advance