Hullo guys , I had to write my own assembly subroutines to be called from C files . From the ARM Cortex-M documentation , it's clear that when an interrupt occur , only R0->R3 , R12 are pushed into stack . So for safe operation , those 're the only registers allowed to be used when interrupts 're enabled ?
Just push and pop all the extra registers you need in case you want to be sure if some of them are used by the compiler.
Example: __asm volatile ( "push {r4}\n\t" "push {r5}\n\t" "push {r6}\n\t"
<Your code in assembler here>
"pop {r6}\n\t" "pop {r5}\n\t" "pop {r4}\n\t" );
Take advantage of the fact that "PUSH" operates on a list of registers: "<reglist>". The ASM can be simplified:
__asm__ volatile("PUSH {R4-R6}\n\t");
__asm__ volatile("POP{R4-R6}\n\t");