GCC Inline Assembly to IAR Inline Assembly

纵然是瞬间 提交于 2019-12-24 07:46:37

问题


I am attempting to use BeRTOS for a Texas Instruments Stellaris Cortex-M3. My work environment is IAR. There were a lot of minor changes to accommodate IAR and the specific uC that I am using but I've got one that I can't seem to solve... and frankly it's a bit over my head.

This bit of code:

1    void NAKED lm3s_busyWait(unsigned long iterations)
2    {
3       register uint32_t __n __asm("r0") = iterations;
4
5       __asm volatile (
6           "1: subs r0, #1\n\t"
7           "bne 1b\n\t"
8           "bx lr\n\t"
9           : : "r"(__n) : "memory", "cc");
10
11    }

... is generating a few errors and warnings.

Error: expected a ";" -----> Line 3

Error: expected a "(" -----> Line 5

Error: expected a ")" -----> Line 9

Warning: variable "__n" was declared but never referenced -----> Line 3

Any suggestions?


回答1:


I'm pretty sure that IAR's compiler doesn't support inline assembly; at least I've always used an actual separate assembly language source file whenever I've need to do things at that level when using IAR's tools.

The code you posted looks like it's more or less equivalent to the following C code:

void lm3s_busyWait( unsigned long iterations)
{
    register volatile unsigned long n = iterations;

    while (--n) {
        /* do nothing */
    }
}

You might be able to use that in place of your version, but it'll be somewhat slower. Whether that matters or not depends on what you're using it for. Compilers generally won't place a volatile in a register, so intead of decrementing a register, the function would likely be hitting a memory location.

The following is a small ARM assembly function that you can put into a file named lm3s_busyWait.s and add it to your IAR project. It should be exactly equivalent to the version you have using GCC's inline assembly:

    /* C prototype:
     *
     *  void lm3s_busyWait( unsigned long iterations);
     *
     */
    PUBLIC  lm3s_busyWait

    SECTION .text:CODE:NOROOT(4)
    THUMB

lm3s_busyWait:
    subs r0, #1
    bne lm3s_busyWait
    bx lr

    end


来源:https://stackoverflow.com/questions/13156795/gcc-inline-assembly-to-iar-inline-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!