【发布时间】:2016-03-13 08:51:43
【问题描述】:
在 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 重写为某种东西……它似乎不喜欢立即值编码?我不擅长组装。
【问题讨论】:
-
不幸的是,Cortex M0+ 没有(大多数)Thumb2 指令。你必须坚持使用
movs r0,#0代替mov r0,#0。 -
您不应该在
r0上声明一个破坏者,或者更好的是,首先要求addr在r0中?"r0"约束有效吗? -
@doynax:这不太对。 M0+ 仅支持 T2 的子集。
-
您为什么要使用 Linux 目标来实现明显的裸机 CPU?看起来像是自找麻烦。
标签: c assembly arm embedded ellcc