Macro problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Metallic-Red

Macro problem

Post 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?
AR

Re:Macro problem

Post 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.
Metallic-Red

Re:Macro problem

Post by Metallic-Red »

Thanks. I tried that and it worked well. :)
richie

Re:Macro problem

Post 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
Post Reply