This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Embed some asm code in C-code file

 

 

Hi, guys,

 

Please help me that how to replace #01h with variables X

#define  __delay_cycles(X) \
 asm(" MOV #01h, R4");\
 asm(" RRC R4");\
 asm(" RRC R4");\
 asm("$1 SUB #1, R4");\
 asm(" JGE $1");\
 asm(" .newblock");

 

 

Thanks.

 

 

  •  

     

     

    #define Quote(x) #x
    #define  __delay_cycles(x) \
     asm(" PUSH R4");\
     asm(" MOV #"Quote(x)", R4");\
     asm(" RRA R4");\
     asm(" RRA R4");\
     asm("$1 SUB #1, R4");\
     asm(" JGE $1");\
     asm(" POP R4");\
     asm(" .newblock")

    // some whitespaces and some format inside were needed.

     

    So...

     

    I might overcome this trouble,

     

    but,

    __delay_cycles(4);

    is ok, 4 is written into R4,

    strangely, __delay_cycles(16);

    other value rather then 16 is loaded.

    Somebody give me a hand, please?

     

     

     

     

     

     

     

**Attention** This is a public forum