7

我目前正在尝试使用汇编加速 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'.
4

3 回答 3

5

小丑说的:

.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
于 2015-06-22T13:23:55.763 回答
3

具有讽刺意味的是,通过使用 UAL 语法来解决第一个问题,您现在遇到的问题几乎相同,但反过来却有一个更神秘的症状。

具有立即操作数的(非标志设置)的唯一 Thumb 编码mov是 32 位的,但是 Cortex-M0 不支持这些,因此汇编程序最终会因自己的约束而窒息。在 UAL 中,您必须明确使用movs才能获得Cortex-M0 实际具有的唯一“立即移动”指令

于 2015-06-22T13:06:42.453 回答
1

在拇指模式下,你不能使用adds,你只有add。因此,正确的代码是:

.cpu cortex-m0
.text
  .global test
  .code 16
test:
  mov r0, #0
  add r0, r0, #1
  bx lr
于 2015-06-22T12:47:45.827 回答