[comp.lang.pascal] Determing the stack size

pilgrimk@lafcol.UUCP (Kenwyn A. Pilgrim) (05/13/89)

I'm having a problem using the {$M x,x,x} directive.
How do I determine how much space I should reserve for the
stack? In the following code for example:

function A(B: byte): byte;
 var C: byte;
 begin
 end;

function D(E:byte): byte;
 var F: byte;
 begin
 end;

begin
 writeln(D(A))
end.

How much memory should be set up for the stack?
I had a hunch that SizeOf(A+B+C+D+E+F) should be reserved, but 
I'm not too sure now that I'm getting stack overflow errors when
implementing this theory. Any help would be appreciated.
Please use e-mail.

Thanks
-Kenwyn

abcscnuk@csuna.csun.edu (Naoto Kimura) (05/14/89)

In article <1110@lafcol.UUCP> pilgrimk@lafcol.UUCP (Kenwyn A. Pilgrim) writes:
>I'm having a problem using the {$M x,x,x} directive.
>How do I determine how much space I should reserve for the
>stack? In the following code for example:
>
>function A(B: byte): byte;
> var C: byte;
> begin
> end;
>
>function D(E:byte): byte;
> var F: byte;
> begin
> end;
>
>begin
> writeln(D(A))
>end.
>
>How much memory should be set up for the stack?
>I had a hunch that SizeOf(A+B+C+D+E+F) should be reserved, but 
>I'm not too sure now that I'm getting stack overflow errors when
>implementing this theory. Any help would be appreciated.
>Please use e-mail.
>
>Thanks
>-Kenwyn

Making a REALLY rough guess:
    2		passing arg to A
    2 or 4	call A
    4		set up stack frame for A
    1 or 2	allocating A.B
    2		passing arg to D
    2 or 4	call D
    4		set up stack frame for D
    1 or 2	allocating D.F
    ------
    14 - 20 bytes *MINIMUM*

    The call to writeln will generate calls to parts of the
    runtime library.  I'm not sure how much that will take up, except
    that there will probably have a minumum of 4 bytes for the calls,
    and 2 bytes for setting up stack frame.

    You will also have to take into account the amount used by any units
    you use.  Range checking and other checks will also affect the
    amount of memory you would require.

                //-n-\\			 Naoto Kimura
        _____---=======---_____		 (abcscnuk@csuna.csun.edu)
    ====____\   /.. ..\   /____====
  //         ---\__O__/---         \\	Enterprise... Surrender or we'll
  \_\                             /_/	send back your *&^$% tribbles !!