[英]How to use thumb-2 instructions with GCC
我編寫了以下簡單的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]
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.