recategorized by
2,945 views
11 votes
11 votes

A stack is used to pass parameters to procedures in a procedure call.

  1. If a procedure $P$ has two parameters as described in procedure definition:

    procedure P (var x :integer; y: integer);

    and if $P$ is called by ; $P(a, b)$

    State precisely in a sentence what is pushed on stack for parameters $a$ and $b$

  2. In the generated code for the body of procedure $P$, how will the addressing of formal parameters $x$ and $y$ differ?

recategorized by

3 Answers

5 votes
5 votes
$a$ is pointer variable so address and $b$ is variable so its value pushed into stack.
edited by
1 votes
1 votes

For part a)

Push a
Push b

Now the producer can be called which then pushes its Return address into the Stack with a pointer SP.
To access these parameters we need to access [SP+2], [SP+4] (Stack fills from higher memory address to lower memory address, so if location 'a' is 10 and 'b' is 8 then SP will be on 6).

http://www.husseinsspace.com/teaching/udw/1996/asmnotes/chapfive.htm

0 votes
0 votes
when procedure P is called with P(a, b), the values of parameters a and b are pushed onto the stack.

Now, in the generated code for the body of procedure P, the addressing of formal parameters x and y will differ based on their positions on the stack. The value of parameter a, corresponding to formal parameter x, will be accessed at a certain offset from the stack pointer. Similarly, the value of parameter b, corresponding to formal parameter y, will be accessed at a different offset from the stack pointer.

Related questions

22 votes
22 votes
3 answers
1
14 votes
14 votes
2 answers
3
Kathleen asked Sep 29, 2014
6,349 views
A part of the system software which under all circumstances must reside in the main memory is:text editorassemblerlinkerloadernone of the above