program t;
{ test recursion
  29 Jan 1987 }

const IMAX=3;
      LMAX=5;

var level: integer;
    pair: integer;

var j: array[0..LMAX] of integer;
    p: array[0..LMAX,0..LMAX] of integer;

{----------------------------------------------------------------------}
function hex(i:integer):char;
begin { function hex }
inline ($CD/$48D);
hex:=Chr(0);
end; { function hex }
{----------------------------------------------------------------------}

procedure rec(l,i:integer;var pp:integer);
{$A-}

begin
writeln;
write  ('Level',l:2,'  Index',i:2);
write  ('  RecurPtr ',Hex(RecurPtr),'  Addr of pp ',Hex(Addr(pp)));
if l=0 then
    begin
    pp:=i;
    end
else
    begin
    j[l]:=1; pp:=0;
    while j[l] <= level-l+1 do
        begin
        rec(l-1,j[l],p[l,j[l]]);
        writeln;
        write  (' Back in level',l:2,'  p[',l,',',j[l],'] = ',Hex(p[l,j[l]]));
        pp:=pp+p[l,j[l]];
        writeln(' pp = ',Hex(pp));
        j[l]:=j[l]+1;
        end;
    end;
end; { procedure rec }

{$A+}

begin { program t }
write(' Start level (>0) '); readln(level);
rec(level,1,pair);
end.

