Intel i960 User Manual page 303

Processor compiler
Hide thumbs Also See for i960:
Table of Contents

Advertisement

Optimization
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;
}
}
11
11-13

Advertisement

Table of Contents
loading

Table of Contents