I'm trying to figure out some kind of builder generated for the stm32f103 chipset using arm-none-eabi-gcc, which seems to work exactly half the speed I expect. I'm not so good at assembler, but since everyone always says they read asm, if you want to understand what your compiler is doing, I can see how far I am. Its simple function:
void delay(volatile uint32_t num) {
volatile uint32_t index = 0;
for(index = (6000 * num); index != 0; index--) {}
}
The clock speed is 72 MHz, and the above function gives me a delay of 1 ms, but I expect 0.5 ms (s (6000 * 6) / 72000000 = 0,0005).
Assembler:
delay:
@ args = 0, pretend = 0, frame = 16
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
sub sp, sp,
movs r3,
str r0, [sp,
str r3, [sp,
ldr r3, [sp,
movw r2,
mul r3, r2, r3 r3 = r2 * r3
str r3, [sp,
ldr r3, [sp,
cbz r3, .L1 Compare and Branch on Zero
.L4:
ldr r3, [sp,
subs r3, r3,
str r3, [sp,
ldr r3, [sp,
cmp r3,
bne .L4 1 branch to .L4 if not equal
.L1:
add sp, sp,
@ sp needed
bx lr
.size delay, .-delay
.align 2
.global blink
.thumb
.thumb_func
.type blink, %function
, , , . , .L4 , 6 . , , , , , , , , , 2 .
:
, , 5 ccd, . ( , ), . , , , ( 100 ) , . , , .
, , , , .
: , arm tech ref . . 9 , 12, . ?
TIA,
, ElderBug, , , . , , , 20 , C , , , gcc, , . BTW Elder wait_cycles , . .