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 ?
Westonsupermare Pier , well I have been working with Cortex for quite 3 yrs now , but its my first time to encounter a situation in which I have to do some components in Assembly . I studied the Cortex-M4 programming manual provided by ST , and also the armasm User Guide but all that provided is the stacking frame . As u r saying its the work of the C compiler , so thats why I did not find much about it in those documentations . Thx for ur help man , and if u recommend further documentations , that would be nice .
The ARM documentation is very, very clear on what registers are preserved and what registers aren't. It's all in the ABI what a function may expect when being called, and what it may expect when calling some other function.
If you need three extra registers, you push three extra registers. Doing it at the start? Maybe. That depends on if you know that you always needs three extra registers. If the code maybe only needs them once every 10 calls then it's better to delay with saving them until your code performs that special magic that does need them. But decisions about what registers to use and when to save them is all part of "engineering", i.e. all the little decisions you need to do in your daily work based on your goals, your needs and the path you have decided to take to reach your goals.