ARM程序集不能同时使用立即值和ADDS/ADCS [英] ARM assembly cannot use immediate values and ADDS/ADCS together
问题描述
我目前正在尝试使用汇编来加快Cortex-M0(Freescale 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'
该错误消息对我而言没有意义,ADDS是根据关于stackoverflow的可能答案,并在开头添加了这一行的程序(".syntax Unified"有效,就像建议的第二个答案一样).这样就解决了这个问题,我现在可以使用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.
具有立即数操作数的(非标志设置) movs
来获取.
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屋!