ARM 程序集不能同时使用立即数和 ADDS/ADCS [英] ARM assembly cannot use immediate values and ADDS/ADCS together

查看:32
本文介绍了ARM 程序集不能同时使用立即数和 ADDS/ADCS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用汇编加速 Cortex-M0(飞思卡尔 KL25Z)上的一些 C 函数.这个最小的测试程序有问题:

I am currently trying to speed up some of my C functions on a Cortex-M0 (Freescale KL25Z) using assembly. I get a problem with this minimal test program:

@.syntax unified
.cpu cortex-m0
.text
  .global test
  .code 16
test:
  mov r0, #0
  adds r0, r0, #1
  bx lr

当我尝试将 .s 文件组装为 .o 文件时,出现此错误

When I try to assemble my .s file to a .o file, I get this error

$ 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'

错误消息对我来说没有意义,根据 本文档.我找到了 stackoverflow 上的一个可能答案 并在开头添加了这一行程序的(.syntax统一"有效,就像建议的第二个答案一样).这导致解决了这个问题,我现在可以使用 ADDS 和 ADCS 等指令,但我确实遇到了一个新错误:

The error message doesn't make sense to me, ADDS is a valid instruction acording to this document. I found a possible answer on stackoverflow and added the line at the beginning of the program (".syntax unified" worked, like the second answer suggested). This resulted in fixing this problem, I can now use instructions like ADDS and ADCS, but I did get a new error:

$ 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 找到解决方案,也不知道如何解决这些错误.

Some instructions using immediate values get this error. I am compiling on Mac OS 10.9.5. I can't find a solution to this via Google or Stackoverflow and have no idea how to get around these errors.

$ 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'.

推荐答案

有点讽刺的是,通过使用 UAL 语法来解决第一个问题,您现在遇到了几乎相同的问题,但反过来说隐匿的症状.

Somewhat ironically, by using UAL syntax to solve the first problem you've now hit pretty much the same thing, but the other way round and with a rather more cryptic symptom.

具有立即操作数的(非标志设置)mov 的唯一 Thumb 编码是 32 位编码,但是 Cortex-M0 不支持这些,因此汇编器最终会卡住它自己的约束.在 UAL 中,您必须明确使用 movs 来获取 Cortex-M0 中唯一的立即移动"指令.

The only Thumb encodings for (non-flag-setting) mov with an immediate operand are 32-bit ones, however Cortex-M0 doesn't support those, so the assembler ends up choking on its own constraints. In UAL you have to explicitly use movs to get the only "move immediate" instruction Cortex-M0 actually has.

这篇关于ARM 程序集不能同时使用立即数和 ADDS/ADCS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆