Page 1 of 1

Macro problem

Posted: Sun Dec 19, 2004 5:48 am
by Metallic-Red
I have made a macro in NASM as follows:

%MACRO PRINT 1
   MOV SI, %1
.start
   MOV AH, 0x0E
   LODSB
   CMP AL, 0x00
   JE .end
   INT 0x10
   JMP .start
.end
%ENDMACRO

Sometimes it workes when I call it but other times it has an error compiling, saying: .end already defined and .start already define or something around those lines. Anyone know how to fix this?

Re:Macro problem

Posted: Sun Dec 19, 2004 6:07 am
by AR
I would think that since .start and .end would be associated with the last main label (One without a '.') that you are using it more than once in a label. One way to fix it would be to put the actual printing code in a function and use the macro to call the function instead of writing the code out repeatedly.

Re:Macro problem

Posted: Sun Dec 19, 2004 6:15 am
by Metallic-Red
Thanks. I tried that and it worked well. :)

Re:Macro problem

Posted: Sun Dec 19, 2004 7:19 am
by richie
You can also create a macro local label with %%start and %%end instead of .start and .end. See the nasm documentation for further information on that topic: http://nasm.sourceforge.net/doc/html/nasmdoc4.html#section-4.3.2