The C compiler views registers in one of three ways:
Temporary – registers whose value need not be preserved (R0, R18:27, R30:31)
If calling assembly from C, there is no need for us to preserve the register(s) in the assembly function.
If calling C from assembly, we should push the register(s) before calling the C function and pop the register(s) immediately following the return (since the C compiler doesn't attempt to preserve the register's value).
Saved – registers whose value must be preserved (R2:17, R28:29).
If calling assembly from C, we must push the register(s) onto the stack at the beginning of the assembly function and pop the register(s) off the stack just prior to returning from the assembly function.
If calling C from assembly, there is no need for us to preserve the register(s) in the assembly function.
R1 – Assumed to have a 0 in it.
If calling assembly from C – the assembly function may use R1 but it must be cleared before returning from the function.
If calling C from assembly – the assembly function must make sure that R1=0 before calling the C function.
ce2810/gcc.txt · Last modified: 2009/06/03 11:22 (external edit)