This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Necessary to save used registers in assembly ?

I am using assembly language routines
called from C code.
Within the assembly routines, is it necessary to save the registers used?

Ex:
MY_ASM_ROUTINE:
PUSH ACC ; necessary ?
CLR A ; overwrite ACC
POP ACC
RET

main(){
MY_ASM_ROUTINE();
}

Or does the C compiler assume that
registers can be overwritten by
calls to routines?

I couldn't find the answer in the manuals.

Thanks in advance
Jim Burke

Parents
  • Thanks for the reply Jon.

    I can therefore assume that the compiler
    will restore registers after a call,
    even if it is optimizing performance by
    using registers. I do not need to
    save used registers in an assembly
    program ( an ISR is an exception ) since
    the caller will assume its registers may have been overwritten.

    Thanks again for your reply.
    It eliminated my doubt.

    Jim

Reply
  • Thanks for the reply Jon.

    I can therefore assume that the compiler
    will restore registers after a call,
    even if it is optimizing performance by
    using registers. I do not need to
    save used registers in an assembly
    program ( an ISR is an exception ) since
    the caller will assume its registers may have been overwritten.

    Thanks again for your reply.
    It eliminated my doubt.

    Jim

Children
No data