When compiling this code
void FastRead()
{
register uint32_t cnt = 1000, sample;
register uint8_t *dst = data;
asm volatile(
"loop1:"
"ldr %[sample], [%[src]]\n\t"
"strb %[sample], [%[dst], #1]!\n\t"
"subs %[cnt],1 \n\t"
"bne loop1\n\t"
: [cnt] "+r" (cnt), [dst] "+r" (dst), [sample] "=r" (sample)
: [src] "r" (&CORE_PIN16_PINREG)
);
}
The register assignment produces this code, after 'compiling'
000004dc <_Z8FastReadv>:
4dc: f44f 737a mov.w r3, #1000 ; 0x3e8
4e0: 4a03 ldr r2, [pc, #12] ; (4f0 <loop1+0xc>)
4e2: 4904 ldr r1, [pc, #16] ; (4f4 <loop1+0x10>)
000004e4 <loop1>:
4e4: 6809 ldr r1, [r1, #0] ; <-- ?!?!?!?!?!?
4e6: f802 1f01 strb.w r1, [r2, #1]!
4ea: 3b01 subs r3, #1
4ec: d1fa bne.n 4e4 <loop1>
4ee: 4770 bx lr
4f0: 1fff8820 .word 0x1fff8820
4f4: 400ff050 .word 0x400ff050
I specified the src to be a read-only register, but should not mean the 'compiler' is allowed to overwrite it, does it? quick workaround is making every variable read/writable (+r).
But what causes this, is this a bug, or can anybody explain me why this is happening?
Edit: sorry forgot to mention, this us on linux using the gcc compiler (arm-none-eabi-g++ both versions 4.7.2 and 4.8.4)