We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
mov A,10
mov A,#10
Perhaps you could use the trigraph for the octothorpe? (??=) Or the digraph? ($:) Or the backslash escape sequence? (\x23 or \043)
I had already tried the trigraph form and verified that it does not work, but stopped there.
hi, this is yet another cause to use assembler language in separate .asm file. Have you the reason to combine with both C and ASM routines in one file really? Regards, Oleg
Do you not have a real name? "The C51 pre-processor treats the "#" character as the "Stringize" operator. How do I override this operator when desired?" Are you saying that the C51 preprocessor is not working in accordance with the standard ANSI rules?
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.
hi, Regardless, it would still be useful to know if it possible to generate a "#" from within a #define macro when using the Ax51 assembler. If you use the assembler and needs with such definitions then I suggest you to use macro. For example:
XCOM MACRO mov A,#10 ENDM
#define XCOM(x) MOV A,x //... somewhere in program: #pragma ASM XCOM(#10) #pragma ENDASM
Thank you Oleg for your useful work-arounds. I have reverted to the 'macro' directive for the subject piece of code, although we will need to maintain separate versions for different assemblers and compilers, which is what we were trying to avoid.