【发布时间】:2016-09-08 11:53:59
【问题描述】:
我编写了以下简单的 memcpy32 函数,作为理解如何为 cortex-m4 编写汇编代码的一种手段。
.section .text
.align 2
.global as_memcpy32
.type as_memcpy32, %function
as_memcpy32:
push {r4, lr}
movs r3, #0
start_loop:
cmp r3, r2
bge end_loop
ldr r4, [r1]
str r4, [r0]
add r0, #4
add r1, #4
add r3, #1
b start_loop
end_loop:
pop {r4, pc}
上面的代码编译并运行。这些只是 16 位指令。我也想使用 32 位 thumb2 指令,因为它们受 Cortex-M4 支持。编写汇编的主要目的是更快地运行我的代码。
我应该可以按照STM32F4手册使用下面形式的ldr和str指令
op{type}{cond} Rt, [Rn], #offset; post-indexed
我正在向 GCC 提供以下选项。
arm-none-eabi-gcc" -c -g -x assembler-with-cpp -MMD -mcpu=cortex-m4 -DF_CPU=168000000L -DARDUINO=10610 -DARDUINO_STM32DiscoveryF407 -DARDUINO_ARCH_STM32F4 -DMCU_STM32F406VG -mthumb -DSTM32_HIGH_DENSITY -DSTM32F2 -DSTM32F4 -DBOARD_discovery_f4 -mthumb -D__STM32F4__ memcpy.S" -o memcpy.S.o
当我尝试对 ldr 和 str 使用以下说明时
ldr r4, [r1], #4
ldr r4, [r0], #4
我收到以下错误。
memcpy.S: Assembler messages:
memcpy.S:11: Error: Thumb does not support this addressing mode -- `ldr r4,[r1],#4'
memcpy.S:12: Error: Thumb does not support this addressing mode -- `str r4,[r0],#4'
exit status 1
Error compiling for board STM32 Discovery F407.
我无法理解问题所在。实际上编译器本身生成了更复杂的寻址操作码。
ldr.w r4, [r1, r3, lsl #2]
str.w r4, [r0, r3, lsl #2]
谢谢
【问题讨论】:
标签: gcc assembly compilation thumb