我目前正在尝试使用汇编加速 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 是根据此文档的有效指令。我在stackoverflow上找到了一个可能的答案,并在程序的开头添加了这一行(“.syntax Unified”有效,就像第二个答案所建议的那样)。这导致解决了这个问题,我现在可以使用 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'.