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
  • Hi Jim,

    I found these documents
    http://www.keil.com/support/docs/939.htm
    http://www.keil.com/support/docs/904.htm
    They tell about REGFILE directives, but both apply to C51 v5.5 and I don't know if they can hel you.

    I understand that REGFILE directives are
    to be used in:
    1. Assembly code (to specify which register are used in each function)
    2. In C compiling parameters (to tell the compiler to optimize register usage following information retrieved in 1.)
    3. In BL51 compiling parameters (why ??)

    I think that if you don't use REGFILE directives C51 compiler assumes that *all* register are corrupted in the Assembly routine, so it "disables" the 'Register variables optimization'.

    Try to analyze the Assembly file created by C51, so you can understand how it uses register to store variables
    first and after Assembly-routine callings. (If C51 v4.10 doesn't allow to create SRC file from C modules use a debugger or a disassembler)

    Tomorrow (in Italy is already 8:00 PM), I hope to make some test.

    Marcello

Reply
  • Hi Jim,

    I found these documents
    http://www.keil.com/support/docs/939.htm
    http://www.keil.com/support/docs/904.htm
    They tell about REGFILE directives, but both apply to C51 v5.5 and I don't know if they can hel you.

    I understand that REGFILE directives are
    to be used in:
    1. Assembly code (to specify which register are used in each function)
    2. In C compiling parameters (to tell the compiler to optimize register usage following information retrieved in 1.)
    3. In BL51 compiling parameters (why ??)

    I think that if you don't use REGFILE directives C51 compiler assumes that *all* register are corrupted in the Assembly routine, so it "disables" the 'Register variables optimization'.

    Try to analyze the Assembly file created by C51, so you can understand how it uses register to store variables
    first and after Assembly-routine callings. (If C51 v4.10 doesn't allow to create SRC file from C modules use a debugger or a disassembler)

    Tomorrow (in Italy is already 8:00 PM), I hope to make some test.

    Marcello

Children