Literalizing the '#' character in #define

The C51 pre-processor treats the "#" character as the "Stringize" operator. How do I override this operator when desired?

For example:

#define X mov A,#10

Expands to:
mov A,10

How can I force a literal expansion of the "#" character such that the above macor expands to:
mov A,#10

Thanks.

Parents
  • Sorry for the "Studio Tech" moniker -- that is the default name on this machine.

    The advice for using a separate ".asm" file (i.e., the A51 "macro" directive instead of "#define") is certainly a workable solution. We do have occasion to generate in-line assembler within C programs and find that a couple of simple #define statements within the ".h" header file is a bit easier to maintain when extensive assembler code is not needed.

    Regardless, it would still be useful to know if it possible to generate a "#" from within a #define macro when using the Ax51 assembler. Regarding ANSI compliance, the A51 User Manual does offer the following two caveats on page 158:
    NOTES
    The Ax51 macro assembler does not accept C escape sequences like "\n", "\r" or
    "\x0d". You need to replace these characters with hex values.

    Unlike the Cx51 compiler, multiple strings are not concatenated to a single
    string by the Ax51 macro assembler. Therefore you need to separate multiple
    items with a comma when using the Ax51 macro assembler.


    I just wish I knew what either of these restrictions meant in terms of actual code construction! As far as I can tell, the C-macro preprocessor within A51 does not expand escape sequences or "hex values" at all.

Reply
  • Sorry for the "Studio Tech" moniker -- that is the default name on this machine.

    The advice for using a separate ".asm" file (i.e., the A51 "macro" directive instead of "#define") is certainly a workable solution. We do have occasion to generate in-line assembler within C programs and find that a couple of simple #define statements within the ".h" header file is a bit easier to maintain when extensive assembler code is not needed.

    Regardless, it would still be useful to know if it possible to generate a "#" from within a #define macro when using the Ax51 assembler. Regarding ANSI compliance, the A51 User Manual does offer the following two caveats on page 158:
    NOTES
    The Ax51 macro assembler does not accept C escape sequences like "\n", "\r" or
    "\x0d". You need to replace these characters with hex values.

    Unlike the Cx51 compiler, multiple strings are not concatenated to a single
    string by the Ax51 macro assembler. Therefore you need to separate multiple
    items with a comma when using the Ax51 macro assembler.


    I just wish I knew what either of these restrictions meant in terms of actual code construction! As far as I can tell, the C-macro preprocessor within A51 does not expand escape sequences or "hex values" at all.

Children
More questions in this forum