Author Topic: Major Problems (Bugs???) with NASM Preprocess  (Read 2249 times)

nobody

  • Guest
Major Problems (Bugs???) with NASM Preprocess
« on: June 12, 2009, 09:37:45 PM »
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?

nobody

  • Guest
Re: Major Problems (Bugs???) with NASM Preprocess
« Reply #1 on: June 12, 2009, 09:45:29 PM »
Well, what do you know, the first thing I tried after I wrote this post worked perfectly:
%macro decdefine 2
%define hn%1 %2
%endmacro
%macro define 2
%assign %%foo %1
decdefine %%foo, %2
%endmacro
Still, I feel that I shouldn't have had to go through all this in order to get this to work; the macro processor needs to be either less buggy or better documented or more powerful.

nobody

  • Guest
Re: Major Problems (Bugs???) with NASM Preprocess
« Reply #2 on: June 12, 2009, 09:47:05 PM »
Err, the code should read
%macro dechandle 2
%define hn%1 %2
%endmacro
%macro handle 2
%assign %%foo %1
dechandle %%foo, %2
%endmacro