This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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
  • 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
    
    Now you may use macro XCOM anywhere in assembly file. And no #define needs.

    If you use C-language and need define some assembly commands which will be used somewhere then I may suggest next way:
    - define it as C-macro:
    #define XCOM(x) MOV A,x
    //... somewhere in program:
    #pragma ASM
    XCOM(#10)
    #pragma ENDASM

    Regards,
    Oleg

Reply
  • 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
    
    Now you may use macro XCOM anywhere in assembly file. And no #define needs.

    If you use C-language and need define some assembly commands which will be used somewhere then I may suggest next way:
    - define it as C-macro:
    #define XCOM(x) MOV A,x
    //... somewhere in program:
    #pragma ASM
    XCOM(#10)
    #pragma ENDASM

    Regards,
    Oleg

Children
No data