search
Log In
8 votes
958 views

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?

in Compiler Design
edited by
958 views
2
Someone please answer this
0

var x:integer means pointer and y:integer means variable

anyone confirm?

2 Answers

4 votes
$a$ is pointer variable so address and $b$ is variable so its value pushed into stack.

edited by
2
how is it identified that a  is pointer variable?
1

@Digvijay Pandey,  can you please explain it?

0
exactly !!!! how did you came to conclusion that the variable a is a pointer.
kindly explain !!!!!!
0

@Digvijay Pandey can you eexplain how is it identify....?????

0
please make your point clear
0
Pointers are language specific i guess. They have not aksed about c language.Some language might not support pointer.Solution should be generic i guess
1
dijvijay sir please explain
0

Since the variable x is passed by reference, it is a pointer to an integer. y is an integer variable. The syntax is of Pascal and it is not in syllabus anymore.

Reference: https://www.tutorialspoint.com/pascal/pascal_procedures.htm

0
Yes I understood the syntax.

But how you came to the conclusion that it is passed by reference?
0
I read the article of tutorial's point.
1 vote

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

Related questions

10 votes
3 answers
1
2.6k views
A part of the system software which under all circumstances must reside in the main memory is: text editor assembler linker loader none of the above
asked Sep 30, 2014 in Compiler Design Kathleen 2.6k views
18 votes
2 answers
2
1.7k views
For the following code, indicate the output if static scope rules dynamic scope rules are used var a,b : integer; procedure P; a := 5; b := 10; end {P}; procedure Q; var a, b : integer; P; end {Q}; begin a := 1; b := 2; Q; Write ('a = ', a, 'b = ', b); end
asked Apr 24, 2016 in Compiler Design jothee 1.7k views
28 votes
6 answers
3
3.6k views
The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions. global int i=100, j=5; void P(x) { int i=10; print(x+10); i=200; j=20; print (x); } main() {P(i+j);} If the ... scoping and call by name parameter passing mechanism, the values printed by the above program are $115, 220$ $25, 220$ $25, 15$ $115, 105$
asked Apr 24, 2016 in Compiler Design jothee 3.6k views
16 votes
2 answers
4
2.2k views
Consider the program below in a hypothetical language which allows global variable and a choice of call by reference or call by value methods of parameter passing. int i ; program main () { int j = 60; i = 50; call f (i, j); print i, j; } procedure f (x, y) { i = 100; x = 10; y = y + ... ; Call by reference :$ i = 100, j = 60$ Call by value : $i = 100, j = 60$; Call by reference :$ i = 10, j = 70$
asked Oct 30, 2014 in Compiler Design Ishrat Jahan 2.2k views
...