I am having trouble understanding this concept. I want to sprinkle some assembly at places in C program where it is slow/can be improved and my preferred way is to write assembly routine in separate file and include it C program where it sees it as a function.
Basically I am doing exactly what they describe in the AT1886 app note.
To reiterate what is mentioned in app note.
- Register r2-r17, r28, r29 - An assembly language routine called from C that uses these registers will need to save and restore the contents of any of these registers it uses.
I get it. So I have to push these registers to stack before using and pop them back at the end of the routine.
- Register r18-r27 ,r30 ,r31 - The registers are available for any code to use. Also described as "Can freely use"
This is the confusion, how can these registers be free to use? Which as I understand, it means there is no need to push/pop them. But how can this be right? What if prior to calling this assembly routine in C program, these registers are in use by C for whatever reason, and I overwrite them in my assembly routine wouldn't that affect the execution of rest of the C program?
Can someone explain this in detail in noob friendly way?
Thank you for your time.