我目前正在尝试使用程序集加速Cortex-M0(飞思卡尔KL25Z)上的一些C函数。我对这个最小的测试程序有疑问:
@.syntax unified
.cpu cortex-m0
.text
.global test
.code 16
test:
mov r0, #0
adds r0, r0, #1
bx lr
当我尝试将.s文件汇编到.o文件时,我收到此错误
$ arm-none-eabi-as test.s -o test.o
test.s: Assembler messages:
test.s:8: Error: instruction not supported in Thumb16 mode -- `adds r0,r0,#1'
错误消息对我没有意义,ADDS是符合this document的有效指令。我找到a possible answer on stackoverflow并在程序开头添加了一行(" .syntax统一"工作,就像建议的第二个答案一样)。这导致修复此问题,我现在可以使用ADDS和ADCS等指令,但我确实收到了一个新错误:
$ arm-none-eabi-as test.s -o test.o
test.s: Assembler messages:
test.s:7: Error: cannot honor width suffix -- `mov r0,#0'
使用立即值的某些指令会出现此错误。我正在Mac OS 10.9.5上编译。我无法通过Google或Stackoverflow找到解决方案,也不知道如何解决这些错误。
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150303 (release) [ARM/embedded-4_9-branch revision 221220]
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ arm-none-eabi-as --version
GNU assembler (GNU Tools for ARM Embedded Processors) 2.24.0.20150304
Copyright 2013 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `arm-none-eabi'.
答案 0 :(得分:3)
有点讽刺的是,通过使用UAL语法解决第一个问题,你现在几乎完全相同,但反过来又有一个更加神秘的症状。
具有立即操作数的(非标志设置)mov
的唯一Thumb编码是32位,但Cortex-M0不支持这些,因此汇编器最终会阻塞它自己的约束。在UAL中,您必须明确使用movs
来获取the only "move immediate" instruction Cortex-M0 actually has。
答案 1 :(得分:3)
.cpu cortex-m0
.text
.thumb
.thumb_func
.global test
test:
mov r0, #0
add r0, r0, #1
bx lr
给出了
0: 2000 movs r0, #0
2: 3001 adds r0, #1
4: 4770 bx lr
或者如果你使用语法统一,那么你必须把s放在那里
.syntax unified
.cpu cortex-m0
.text
.thumb
.thumb_func
.global test
test:
movs r0, #0
adds r0, r0, #1
bx lr
也给出了
00000000 <test>:
0: 2000 movs r0, #0
2: 3001 adds r0, #1
4: 4770 bx lr
答案 2 :(得分:1)
在拇指模式下,您无法使用adds
,只有add
。因此,正确的代码是:
.cpu cortex-m0
.text
.global test
.code 16
test:
mov r0, #0
add r0, r0, #1
bx lr