Menu

#190 Is it possible to have inline assembler to load constant created by define?

open
nobody
None
5
2023-07-01
2023-07-01
Deqing Sun
No

Hi,

I tried to create some constant in C with #define such as

#define TL0_RECV_START_VALUE 0

And load it into registers. But it seem SDCC can not replace the text with value. How can I do that. Now I put the value into an SFR in C and have the inline assembler to read it back. It seems in efficient.

Discussion

  • Benedikt Freisen

    I don't know whether there is any way to use C preprocessor macros in combination with the old inline assembly syntax, but it should be possible with the C-compliant syntax that uses string constants:

    #define MY_MACRO "0"
    __asm__(
        "mov a,1 \n"
        "add a," MY_MACRO "\n"
        "add b,a \n"
    )
    

    Add some preprocessor stringification magic if you want to work with a literal 0.

     
  • Deqing Sun

    Deqing Sun - 2023-07-01

    Thank!

    #define TL0_RECV_START_VALUE 64
    #define STR_INDIR(x) #x
    #define STR(x) STR_INDIR(x)
    "    mov r6,#" STR(TL0_RECV_START_VALUE) "    \n"
    

    got compiled to

    mov r6,#64 
    

    Awesome!

     

Log in to post a comment.

MongoDB Logo MongoDB