Chapter 6: Runtime System

Stack Allocation .

. The return sequence consists of two parts.

. The called procedure transfers control to the return address using

GOTO *0(SP)

0(SP) is the address of the first word in the activation record and *0(SP) is the return address saved there.

. The second part of the return sequence is in caller which decrements SP

SUB #caller.recordsize, SP

The value that was referred to by *SP while making the call, is here being referred to as *O(SP). What this means is that the return address previously stored by the caller is now being used by the callee to return back to the caller's code. After this, the caller is removed from the stack by deleting the caller's record size from the stack. So at any point in time, the current activation is not on the stack, but the activations of the function which called it, the function which called that, etc. are on the stack. The code for SUB #caller.recordsize, SP needs to be in the caller, as only the caller has access to #caller.recordsize as a constant.