Here is my C Code:
void combinationComputer(int* temp, int* arr, int* data, int start, int end,
int index, int k, int* x, int* y, int count) {
int i;
if (index == k) {
if (count > k) {
*x = *x + k;
*y = *y + k;
}
for (i = *x; i < *y; i++)
temp[i] = data[i - *x]; // storing all combinations into temp[] as a
// single chunk, one combination at a time
return;
}
for (i = start; i <= end && end - i + 1 >= k - index; i++) {
data[index] = arr[i]; // each combination is stored in data[], with each
// subsequent combination overwriting the previous
// one.
count = count + 1;
combinationComputer(temp, arr, data, i + 1, end, index + 1, k, x, y,
count); // recursive call
}
}
What this function does is not very relevant to the question, I'm just stuck on the for loop after return. See this for loop calls the function recursively. Eventually the for loop will not hold true, and it will just exit the function by reaching the last brackets.
In C, this automatically returns control back to the parent call to combinationComputer, inside this for loop. I'm not sure how to implement this in assembly. Is there a specific name for this behavior in C? (Is it tail-call elimination)?
Basically what I am asking is what is the behavior called when you exit (by reaching the last bracket) a function called recursively and it returns to the parent call. How can this be implemented in assembly (no code please, just logic) If you need more information please ask.
voidfunction which reaches the ending brace performs a return, just as though you'd putreturn;there explicitly. It's done exactly the same as the firstreturn;, usually with aretinstruction. Tail-call elimination is something else entirely, and it's inapplicable here because the recursive calls are not in tail position.-S(captial 'S')). Then you can edit that for readability and tweaking.