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

Writing ARM application containing both C code and assemply code

Note: This was originally posted on 6th September 2007 at http://forums.arm.com

Hi I need to put one ARM instruction in ARM application written in C.
Basically my application looks like
void main(void)
{
  ................
   ................
   enable_IRQ();
   program_dma();   /* programs DMA with st address, dest addr, xfer length etc and enables DMA*/
   /* Here I want to put a ARM instruction(assembly) */
   ..............
}

Extra information:
            After enabling DMA, I want to execute WaitForInterrupt instruction by doing

MCR p15, 0, Rd, c7, c0, 4

Since this is C code I cant directly put that instruction( I guess).
Can you tell me how can I put that MCR instruction in my C code
  • Note: This was originally posted on 6th September 2007 at http://forums.arm.com

    Than you Rajesh.
  • Note: This was originally posted on 12th September 2007 at http://forums.arm.com

    Hi pavan,
      One more thing to add ,
      you can not use MCR instruction in user mode.So if you are running c code in user mode then using use swi instruction in assmbely to change from user mode to SVC mode.
    Zameer
  • Note: This was originally posted on 12th September 2007 at http://forums.arm.com

    __asm void WFI(void)
    {
       MCR p15,0,r0,c7,c0,4;  // wait-for-interrupt
       BX lr;  // return from function
    }


    Should I be able to use
    __asm
    {
       WFI
    }

    The RVDS compiler does not like this for some reason, but accepts the MCR... line ok.  Are these equivalent?
  • Note: This was originally posted on 14th September 2007 at http://forums.arm.com

    The WFI instruction and the earlier cp15 equivalent have different encodings; your compilation target may not support the WFI instruction.

    hth
    s.


    I am workign on an ARM7TDMI - I thought this supported the full Thumb 2 instruction set.  Perhaps the compielr does not support Thumb 2...
  • Note: This was originally posted on 14th September 2007 at http://forums.arm.com

    I am working on an ARM7TDMI - I thought this supported the full Thumb 2 instruction set.  Perhaps the compiler does not support Thumb 2...

    Looks like ARM7 does not support Thumb 2 - is there any equivalent fucntionality on ARM7 or do I require external circuitry to go into a low power mode?
  • Note: This was originally posted on 6th September 2007 at http://forums.arm.com

    Hi I need to put one ARM instruction in ARM application written in C.
    Basically my application looks like
    void main(void)
    {
      ................
       ................
       enable_IRQ();
       program_dma();   /* programs DMA with st address, dest addr, xfer length etc and enables DMA*/
       /* Here I want to put a ARM instruction(assembly) */
       ..............
    }

    Extra information:
                After enabling DMA, I want to execute WaitForInterrupt instruction by doing

    MCR p15, 0, Rd, c7, c0, 4

    Since this is C code I cant directly put that instruction( I guess).
    Can you tell me how can I put that MCR instruction in my C code


    hi

    The ARM C compilers support inline assembly language with the __asm specifier.

    you can use the following code for writing assembly code in C code

    void program_dma()

    {

    __asm
    {
    MCR p15, 0, Rd, c7, c0, 4
    }

    }
    you can use any number of instructions inside the brackets

    regards,
    Rajesh
  • Note: This was originally posted on 14th September 2007 at http://forums.arm.com

    Looks like ARM7 does not support Thumb 2 - is there any equivalent fucntionality on ARM7 or do I require external circuitry to go into a low power mode?


    ARM7 definitely does not support Thumb-2.  It is only available in the newer cores (e.g. ARM1156T2-S, and most of the Cortex family processors.)

    You ought to read the technical documentation that comes for your processor.  That should tell you the instruction you need to issue to achieve your goal.  The equivalent MCR instruction that does a WaitForInterrupt on cores earlier than Cortex is shown above, but you'll need to check your processor's technical documentation to check if it's correct.
  • Note: This was originally posted on 13th September 2007 at http://forums.arm.com

    The WFI instruction and the earlier cp15 equivalent have different encodings; your compilation target may not support the WFI instruction.

    hth
    s.
  • Note: This was originally posted on 10th September 2007 at http://forums.arm.com

    Pavan,

    ARMCC also provides "embedded" assembler which allows simple creation of assembler functions within C source code; for example, your code could become:

    __asm void WFI(void)
    {
       MCR p15,0,r0,c7,c0,4;  // wait-for-interrupt
       BX lr;  // return from function
    }

    which could then be called from other C code via the standard C function method, e.g. WFI();.

    The use of linker inlining would allow the linker to replace the call to your WFI() function with the MCR itself, producing code similar to that of the inline assembler.

    hth
    s.
  • Hi pavan,

    You can also try for ARM intrinsics for WFI instructions with respect to your ARM core which you are using. That helps you better in programming.