I am having some trouble with the NASM preprocessor. What I'm trying to do is this: create a multiline macro (called handle) that, given a number (in any format) and a string, defines the symbol hnDDD as the string, where DDD is the decimal version of the string. For example, handle 0x20 clockhandler would first expand to %define hn32 clockhandler, then preprocessing would continue as if I had just wrote %define hn32 handler. I have naively tried
%macro 2
%assign foo %1
%define hn%[foo] %2
%endmacro
. To test it, I put the two code lines
handle 32 bleh
blob equ hn32
below this macro definition. The code silently fails; the preprocessed code reads "blob equ hn32". This also has the added disadvantage that foo is modified by the macro. I tried
%macro 2
%assign %%foo %1
%define hn%%foo %2
%endmacro
in an attempt to correct both problems. Once again, blob equ hn32 is put into the source; %define hn%[%%foo] %2 does the same.
Then I tried doing
%define mydefine(x, y) %define x y
%macro 2
%assign %%foo %1
mydefine(hn%%foo, %2)
%endmacro
This resulted in a %define
hn..@3.foo bleh line being put in the preprocessed code, which isn't understood by the assembler. Replacing with mydefine(hn%[%%foo], %2) paradoxically resulted in the line %define hn%[32] bleh being put in the code, which also isn't understood by the assembler. I also tried not doing the %%foo thing and doing just plain foo with all this and also making mydefine a multiline macro and also making more helper macros with paramater concatenation and all sorts of other stuff, but long story short this post is already way too long and I don't want to bother explaining the rest of it. How do I make this macro work? Is the preprocessor working like it should?