首页 > 解决方案 > 编译内置 asm 时出错

问题描述

我最近从 Keil Uvision 切换到我自己的 Makefile 我在编译文件 port.c 时遇到问题,文件中的函数:

__asm void vPortSVCHandler( void )
{
    PRESERVE8

    /* Get the location of the current TCB. */
    ldr r3, =pxCurrentTCB
    ldr r1, [r3]
    ldr r0, [r1]
    /* Pop the core registers. */
    ldmia r0!, {r4-r11, r14}
    msr psp, r0
    isb
    mov r0, #0
    msr basepri, r0
    bx r14
}

编译时出现以下错误:

../port.c:52:7: error: expected '(' before 'void'
   52 | __asm void vPortSVCHandler( void )
      |       ^~~~
      |       (
../port.c:64:13: error: stray '#' in program
   64 |     mov r0, #0

我是否缺少包含或编译器选项?

标签: cgccmakefile

解决方案


您使用gcc和 gcc 没有“asm”功能。

您需要在汇编程序中编写它或编写内联汇编。__asm也不是有效的gcc关键字。

https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html


推荐阅读