I call a short and easy function out of an timer interrupt. This causes the c51 compiler to push all registers (A, B, DPH, DPL, PSW AR0..AR7) to the stack without any necessarity (they are not changed in this function). The fuction I call is in a seperate *.c file. How can I tell the C51-Compiler not to do this to save dataRAM and runtime? I can not use the using functionality because of register access.
You could consider assembler for the interrupt - Then you can be totally explicit about what you push and pop.
You say the function you call does not change certain registers - But what happens if you modify the function, or use a newer/different version of the compiler? A different combination of registers might end up being used and you would have to change your interrupt accordingly.
Hy, thanks for this information. I was already thinking about assembler, but I want the compiler to do this, because it is possible. The comiler pushes even all registers, when the called function is an empty "dummy" function!
because it is possible
You might want to look at Global Register Coloring in the manuals. I have not used it myself, but it might do the job.
Hy, I tested the global register coloring and it solved my problem. I was looking for this point of optimazation on my local help, but on my installation exact this point is not described. So I took a look into the internet and saw that this is what I was searching for.
Thanks a lot for your help!
Where does the pushing of registers occur?
What, exactly, causes it?
"without any necessarity"
Remember that code generated by the compiler has to be completely general - although you can see that there may be no neccessity in your specific case, the compiler's generated code has to cope with all cases...
Taking advantage of such "insider information" is, of course, one of the key ways that an assembler programmer can beat a compiler!
"How can I tell the C51-Compiler not to do this"
Have you looked at:
http://www.keil.com/support/man/docs/c51/c51_le_regbankspec.htm
See also: http://www.keil.com/support/man/docs/c51/c51_le_interruptfuncs.htm
http://www.keil.com/support/man/docs/c51/c51_ap_regusage.htm
Hello Anrew, thanks for your help, I solved the problem with the "global register coloring" and it works!
This causes the c51 compiler to push all registers (A, B, DPH, DPL, PSW AR0..AR7) to the stack without any necessarity
and is that 'using' other than zero?
Erik
Hello Erik, what do you mean? The registers are pushed to the stack, but they are not changed by the interrupt function.
void blah (void) interrupt using n { blong(); }
void blong(void) using n
the function and the interrupt do not work with a using. this is not possible because of register addressing on other places of the code.
why not, are you, in fact, calling the function from both interrupt and main
"why not, are you, in fact, calling the function from both interrupt and main"
If he were, then surely the Global Register Coloring operation would complain and/or fail.
Hello, the called function ist called from the int and from the "normal" program. but the global register coloring is working correct!!
A good thing to do for 8051 programs is to have the interrupt handler use a different register bank and to make special copies of all functions that needs to be called from the ISR, that also makes use of this register bank.