在 Gnu G++ 中成功使用的已知有效指令在此处对 Freescale MKL16Z Cortex-M0+ Thumb2 造成了一些错误
编码:
/* setup the stack before we attempt anything else
skip stack setup if __SP_INIT is 0
assume sp is already setup. */
__asm (
"mov r0,%0\n\t"
"cmp r0,#0\n\t"
"beq skip_sp\n\t"
"mov sp,r0\n\t"
"sub sp,#4\n\t"
"mov r0,#0\n\t"
"mvn r0,r0\n\t"
"str r0,[sp,#0]\n\t"
"add sp,#4\n\t"
"skip_sp:\n\t"
::"r"(addr));
编译命令:
ecc -target thumb-linux-engeabi -mtune=cortex-m0plus -mcpu=cortex-m0plus -mthumb -O2 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -Wconversion -Wpointer-arith -Wshadow -Wfloat-equal -g3 -I"[redacted]" -I"[redacted]" -I"[redacted]" -I"[redacted]" -std=c99 -MMD -MP -MF"Project_Settings/Startup_Code/startup.d" -MT"Project_Settings/Startup_Code/startup.o" -c -o "Project_Settings/Startup_Code/startup.o" "../Project_Settings/Startup_Code/startup.c"
../Project_Settings/Startup_Code/startup.c:209:17: error: instruction requires: arm-mode
"sub sp,#4\n\t"
^
<inline asm>:6:2: note: instantiated into assembly here
mov r0,#0
^
../Project_Settings/Startup_Code/startup.c:210:17: error: invalid instruction
"mov r0,#0\n\t"
^
<inline asm>:7:2: note: instantiated into assembly here
mvn r0,r0
^~~
2 errors generated.
make: *** [Project_Settings/Startup_Code/startup.o] Error 1
提示赞赏!我想知道我是否可以使用更简单的指令将 asm 重写为某种东西……它似乎不喜欢立即值编码?我不擅长组装。