NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: gammac on June 01, 2014, 08:00:24 AM
-
Hello everybody!
I am new to nasm and this forum. My english is ... a shame, sorry.
My question is, why doesn't %comment and %endcomment work?
I use %if 0 ... %endif instead, but, maybe I missunderstand something with
%comment and %endcomment
I use the win32 NASM version 2.11.05 compiled on May 21 2014
and get the following errors:
empty.asm:2: error: unknown preprocessor directive `%comment'
empty.asm:2: error: label or instruction expected at start of line
empty.asm:3: error: unknown preprocessor directive `%endcomment'
empty.asm:3: error: label or instruction expected at start of line
thank you
-
Hi Gammac!
Good question. That's a fairly new macro command. To tell the truth, I thought, "there's no such thing". I don't know when it was added. But I can confirm that it's documented, and that it doesn't work. Use %if 0 as a workaround, I guess.
Best,
Frank
-
%comment/endcomment was added quite some time ago, iirc by Keith. It was later taken out around the same time that the code for recursive macros was removed, not sure why though. It's been gone for quite some time and I don't think anyone has really noticed, till now. It probably should just be removed from the documentation. It was a good idea, though not sure it's worth reimplementing.
-
Since programmers still read this post, here's my two cents:
I just use two macros and either put them in my current program or a separate macro include file.
;----------------------------------------------------------------------
; _COMMENT (no parameters)
; _ENDCOMMENT (no parameters)
; PURPOSE: Provide multi-line comment capability
; USAGE: _COMMENT
; statements commented out
; _ENDCOMMENT
;----------------------------------------------------------------------
%imacro _COMMENT 0
%push COMMENT ; Push context
%ifndef __COMMENT ; Check that any previous COMMENT includes
%define __COMMENT ; a closing ENDCOMMENT directive
jmp %$endcomment ; Skip over all statements until ENDCOMMENT
%else
%error "_ENDCOMMENT missing after previous COMMENT directive!"
%endif
%endmacro
%imacro _ENDCOMMENT 0
%ifctx COMMENT ; Verify context
%$endcomment: ; Jump here from COMMENT macro
%undef __COMMENT ; Undefine __COMMENT
%pop COMMENT ; Remove context
%else
%error "Missing _COMMENT directive before _ENDCOMMENT!"
%endif
%endmacro
I use the _comment/_endcomment to comment-out parts of code I'm testing. That way I don't have to remove the code or use semi-colons to do the same job.
Logman
-
Hi Logman,
The appropriate way is to use
%if 0
instead of
jmp %$endcomment
and
%endif
instead of
%$endcomment:
This way, you can really have any text in the block not just valid assembler mnemonics.
Also the code you comment won't be part of the output file (executable).
EDIT : I realized that %if 0 & %endif cannot be accomodated in your macro .
so I think I am just going to say that %if 0 , %endif can be a better way.
-
%comment/endcomment was added quite some time ago, iirc by Keith. It was later taken out around the same time that the code for recursive macros was removed, not sure why though. It's been gone for quite some time and I don't think anyone has really noticed, till now. It probably should just be removed from the documentation. It was a good idea, though not sure it's worth reimplementing.
Oh so it's been taken out, so that's why it doesn't work. It should be taken out of the documentation then to avoid confusion. Can Keith put %comment back in in the future?