GATE / CS ARCHIVE

GATE CSE 1993 / QUESTION 26(b)

Addressing formal parameters

Compiler Design · Runtime Environments & Parameter Passing · Full GATE CSE 1993 paper

GATE 1993, Q26(b) Descriptive
Report issue

Runtime Environments & Parameter Passing

Question 26(b), GATE 1993: Procedure P(var x:integer; y:integer) receives the address of actual a and value of actual b on its stack. How does generated addressing for x differ from y?
Question 26(b), GATE 1993: Procedure P(var x:integer; y:integer) receives the address of actual a and value of actual b on its stack. How does generated addressing for x differ from y?
Question 26(b), GATE 1993: Procedure P(var x:integer; y:integer) receives the address of actual a and value of actual b on its stack. How does generated addressing for x differ from y?
Tap to enlarge
Answer & solution

Answer: x uses an indirect load/store through its pointer slot; y uses its own value slot directly. (no official key was published)

With a frame pointer FP and symbolic offsets ox,oy, the slot at FP+ox contains an address, whereas the slot at FP+oy contains an integer. To read x, first load ptr:=memory[FP+ox], then load memory[ptr]. To assign x:=v, store v into memory[ptr]. These operations reach the caller's a.

To read y, load memory[FP+oy] directly. To assign y:=v, store v into that same local argument slot. This changes the callee's copied value, not b. Thus reference-parameter access has one extra level of indirection relative to a direct stack-slot value parameter, even if a machine's addressing modes combine the micro-operations in one instruction.

The offsets remain symbolic because the source specifies neither stack layout nor saved control fields. If the compiler caches a parameter in a register, it must preserve the same observable aliasing behavior; such optimization does not change the semantic distinction being asked about.

Original paper, page 14