Hello, I write some code for a microcontroller (251 family) in C language. depending on some stuff, i will continue in a way or another way, so i will call the desired function as Function(); This will lead to an ECALL in asm, which mean PC up on the stack.. How can i explain to compiler that a EJMP is desired in my case, i do not need to come back ever, i do not need the PC on the stack (remember, i do this in C...) The function called is (also) in another C file (not the same file), where there are more files into one project. Any suggestion would be appreciated, thanX
How can i explain to compiler that a EJMP is desired in my case, i do not need to come back ever, i do not need the PC on the stack (remember, i do this in C...)
There's no way in plain C. But all any decent C compiler's optimizer will need to do this is that there's nothing in the calling function after the call. I.e.
void caller(void) { /* do something */ called_function(); }
while not guaranteed to, is highly likely to end up as a jump to called_function(), instead of a call.
"while not guaranteed to, is highly likely to end up as a jump to called_function(), instead of a call."
For your benefit Ioan, since Hans-Bernhard almost assuredly knows this, a function that is always at the end of a call tree is known as a "leaf function". That is a term you may encounter when investigating this type of optimization.