xGe*_*ntx 5 assembly gcc arm instructions
我目前正在尝试使用汇编来加快Cortex-M0(Freescale KL25Z)上的某些C函数的速度。我对这个最小的测试程序有疑问:
@.syntax unified
.cpu cortex-m0
.text
.global test
.code 16
test:
mov r0, #0
adds r0, r0, #1
bx lr
Run Code Online (Sandbox Code Playgroud)
当我尝试将.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'
Run Code Online (Sandbox Code Playgroud)
该错误消息对我而言没有任何意义,根据该文档,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'
Run Code Online (Sandbox Code Playgroud)
一些使用立即值的指令会出现此错误。我正在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'.
Run Code Online (Sandbox Code Playgroud)
小丑说的话:
.cpu cortex-m0
.text
.thumb
.thumb_func
.global test
test:
mov r0, #0
add r0, r0, #1
bx lr
Run Code Online (Sandbox Code Playgroud)
这使
0: 2000 movs r0, #0
2: 3001 adds r0, #1
4: 4770 bx lr
Run Code Online (Sandbox Code Playgroud)
或者如果你使用统一的语法,那么你必须把 s 放在那里
.syntax unified
.cpu cortex-m0
.text
.thumb
.thumb_func
.global test
test:
movs r0, #0
adds r0, r0, #1
bx lr
Run Code Online (Sandbox Code Playgroud)
这也给
00000000 <test>:
0: 2000 movs r0, #0
2: 3001 adds r0, #1
4: 4770 bx lr
Run Code Online (Sandbox Code Playgroud)
有点讽刺的是,通过使用 UAL 语法来解决第一个问题,您现在遇到了几乎相同的问题,但相反,并且具有更神秘的症状。
具有立即操作数的(非标志设置)唯一的 Thumb 编码mov是 32 位编码,但是 Cortex-M0 不支持这些编码,因此汇编器最终会因其自身的限制而陷入困境。在 UAL 中,您必须显式使用movs来获取Cortex-M0 实际上具有的唯一“立即移动”指令。
| 归档时间: |
|
| 查看次数: |
3957 次 |
| 最近记录: |