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
  • I'm a new user of Keil products, and i've the same problem.
    But at page 135 of 'C51 Compiler User's Guide (01.97)' you can read:
    "Assembler functions can change all register contents in the current selected register bank as well as the content of th register ACC, B, DPTR, PSW. [..]".
    IMHO this behaviour seems to be not optimized.
    The best solution seems to be REGFILE directives of C51 and BL51. But I don't know how they work. I will investigate.

    Marcello

Reply
  • I'm a new user of Keil products, and i've the same problem.
    But at page 135 of 'C51 Compiler User's Guide (01.97)' you can read:
    "Assembler functions can change all register contents in the current selected register bank as well as the content of th register ACC, B, DPTR, PSW. [..]".
    IMHO this behaviour seems to be not optimized.
    The best solution seems to be REGFILE directives of C51 and BL51. But I don't know how they work. I will investigate.

    Marcello

Children