Tail recursion is a special case. You do not need to use any of the local variables again and the only time you will be passing this way again is in a cascade of Returns heading towards the original caller.
Therefore tail recursion looks like a jump instruction preceeded by code to set the local variables as required for the new call. Contrary to normal recursion there will be exactly one call and one return. The return will be the one where you escape from the recursion.
Code: Select all
/* Assembler sets up the stack frame here */
if (n < 10):
/* Assembler tears down stack frame here, or jumps to the end of the function and does it there */
n = n - 10;
The assembler will be a little complicated by having to avoid all the fiddling about setting the stack up at the beginning. You probably want to loop back to just after that.