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

Keil ARM inline assembly

I want to insert inline assembly for following statements .I have used __asm directive but it gives error messege

mrs r4, CPSR
orr r4, r4, #0xC0
msr CPSR, r4

kindly advice

Parents
  • this is the code

    __asm  {
              MRS R0 ,CPSR  			  AND R0,R0,#0XFFFFFF7F
              MSR CPSR,R0 }
    
    .

    error message shown is
    *** MRS R0 ,CPSR
    HELLO.C(31): error C197: inline-asm: undefined identifier
    *** MRS R0 ,CPSR
    HELLO.C(31): error C197: inline-asm: Syntax error
    HELLO.C(33): error C197: inline-asm: Register name expected
    *** MSR CPSR,R0
    HELLO.C(35): error C197: inline-asm: undefined identifier
    *** MSR CPSR,R0
    HELLO.C(35): error C197: inline-asm: Syntax error

    I am using keil Arm first time kindly advice

Reply
  • this is the code

    __asm  {
              MRS R0 ,CPSR  			  AND R0,R0,#0XFFFFFF7F
              MSR CPSR,R0 }
    
    .

    error message shown is
    *** MRS R0 ,CPSR
    HELLO.C(31): error C197: inline-asm: undefined identifier
    *** MRS R0 ,CPSR
    HELLO.C(31): error C197: inline-asm: Syntax error
    HELLO.C(33): error C197: inline-asm: Register name expected
    *** MSR CPSR,R0
    HELLO.C(35): error C197: inline-asm: undefined identifier
    *** MSR CPSR,R0
    HELLO.C(35): error C197: inline-asm: Syntax error

    I am using keil Arm first time kindly advice

Children
  • As I said to you before, You should just read the message literally - and think what it's telling you.
    (I actually said it twice - but that was just an accident!)

    The messages say, "undefined identifier" and "Register name expected" - so it looks like it's not recognising CPSR and R0.

    Probably, you are missing an include file or something...?

    Why do you particularly want to do this as inline assembler?

  • You need to make sure that the inline assembly code within the function uses the correct mode: either ARM or Thumb, default is Thumb and that's why you get the errors since you are using ARM instructions. You can override the function mode with __arm or use #pragma ARM to change it. Take a look at the following example:

    // #pragma ARM  // would do the same as __arm below !
    void ChangeIRQ (unsigned int NewState) __arm  {  // use ARM-mode for this function
      __asm  {
         AND    R0,R0,#0         //
         MRS    R0,CPSR          //
         ORR    R0,R0,#0x80;     //
    
         LDAV   R1,R10,NewState  // load parameter-value 'NewState' into R1
         BIC    R0,R0,R1,LSL #7  //
         MSR    CPSR_c, R0       //
      }
    }