EasyManua.ls Logo

Intel i960 - Page 303

Intel i960
347 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Optimization
11-13
11
For example, the following algorithm for Ackermann's function uses tail
calls:
/* Ackermann's function with tail recursion */
int ack(int m,int n)
{
if (m == 0)
return n+1;
else
if (n == 0)
return ack(m-1,1);
else
return ack(m-1,ack(m,n-1));
}
Tail-call recursion elimination produces the following:
/* Ackermann's function with tail recursion eliminated */
int ack(int m,int n)
{
label:
if (m == 0)
return n+1;
else
if (n == 0)
{
n=1;
m--;
goto label;
}
else
{
n = ack(m,n-1);
m--;
goto label;
}
}

Table of Contents

Related product manuals