NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: mark allyn on August 21, 2009, 12:51:19 AM
-
Hi everyone - the following Macro produces error messages when invoked. The SWITCH macro generates an error message that says: comma, colon, or end of line expected, and the CASE macro produces an error message that says: label or instruction expected at start of line.
%macro SWITCH 1
%push switch
%assign __curr 1
mov eax, %1
jmp %$loc(__curr) ;%$loc(__curr)
%endmacro
%macro CASE 1
%ifctx switch
%$__curr: ;loc(__curr):
%assign __curr __curr+1
mov ebx, %1
cmp eax, ebx
jne __curr ;%$loc(__curr)
%endif
%endmacro
I have been thru this code a whole bunch of times and can't see what ails it.
If anyone has a clue or suggestion, I would be grateful.
Ciao,
Mark Allyn
-
Well, the first error is because Nasm doesn't like the parentheses. The second error is because an identifier (your "__curr:" label is "1:", etc.) may not begin with a number (took me a while to figure that one out!). If you use "%$loc%$__curr", Nasm will make labels like "..@1.loc1 (http://mailto:..@1.loc1):". "..@1.loc2 (http://mailto:..@1.loc2):", etc. You'll need an "ENDSWITCH" macro to generate the final label, or Nasm will complain that it's undefined. I imagine you'll want a "DEFAULT" macro, too - and some error checking in case some "user" tries to use CASE before SWITCH or after DEFAULT, etc... Trashing eax and ebx in a macro isn't too great...
Good luck, Mark!
Best,
Frank
-
I should mention, in "case" you're not aware of it, the "-e" switch will cause Nasm to "preprocess only" (to stdout). This can be useful in debugging macros - shows what's getting passed to the "assemble" stage. It doesn't do well on forward references, but is still some help. Macros are a PITA to debug, in any "case"!
Best,
Frank
-
Hi Frank -
Man oh man, I would never have come up with that solution. I can't dig it out of the NAsM manual.
I was sure too that it was a problem with the %$loc(___curr) and tried all kinds of ways to rewrite it. Even looked for the thing on GOOGLE. Nothing I tried could fix it.
Thanks a bunch,
Mark