Reputation: 71
I have written the following simplistic memcpy32 function, as a means of understanding how to write assembly code for the 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}
The above code compiles and runs. These are only 16bit instructions. I want to use 32 bit thumb2 instructions also as they are supported by the Cortex-M4. And the main point of writing assembly is to run my code faster.
I should be able to use the following form of the ldr and str instruction according to the STM32F4 manual
op{type}{cond} Rt, [Rn], #offset; post-indexed
I am supplying the following options to the 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
When I try to use the following instructions for ldr and str
ldr r4, [r1], #4
ldr r4, [r0], #4
I get the following errors.
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.
I am not able to understand what the problem is. Actually the compiler itself generated a lot more complex addressing opcode.
ldr.w r4, [r1, r3, lsl #2]
str.w r4, [r0, r3, lsl #2]
thanks
Upvotes: 2
Views: 6112
Reputation: 71
I just found that I should say
.syntax unified
below
.section
The following topic deals with other things, but I saw it there and tried. It worked.
How to generate the machine code of Thumb instructions?
Upvotes: 3