The communication between a calling procedure and called procedure is done by means of nonlocal names and parameters. The common methods for associating actual parameters with the formal parameters are:
- Call by value :
This is the simplest method of passing parameters. The calling procedure evaluates the actual parameters and passes their resulting value to the called procedure which treats a formal parameter as a local name and keeps this value in the storage for the formal parameters in the activation record of the called procedure. We may note that the operations on the formal parameters do not affect values in the activation record of the caller.
- Call by reference :
The calling procedure passes a pointer to the storage location of each actual parameter to the called procedure. A reference to the formal parameters, then, becomes an indirect reference through the address passed to the called procedure. This method of passing parameters is used by many programming languages
- Copy restore :
the method is also known as the copy-in copy-out method. The actual parameters are evaluated and the resulting values are passed to the called procedure. This step copies the values of the actual parameters into the storage for the parameters in the activation record of the called procedure. After execution, the current values of the formal parameters a copied back into the address of the actual parameters. This set copies out the final values of the formal parameters Into the activation record of the calling procedures. This method is a hybrid between call by value and call by reference and is used by some FORTRAN implementations.
4, Call by name :
Whenever a procedure is called, the effect is that of substituting the procedure body for the procedure call in the calling procedure, with the actual parameters literally substituted for the formal parameters.
The local names of the called procedure are kept different from that of the calling procedure. Name clashes; if any, are resolved by systematically renaming. This method is also known as macro expansions.
The procedure calls are implemented by generating calling sequences in the target code which allocates an activation record and enters information into its fields. Similarly, the return sequence restores the state of various registers so that the calling procedure can continue execution. This bookkeeping work is divided between the calling procedure (caller) and the called procedure (callee) as follows:
- Call sequence
(a) Caller’s activities
(i) Saves the actual parameters on the stack.
(ii) Sets Use static link.
(iii) Makes space on the stack to save the return value.
(iv) Branches to the called procedure and saves the return address on the stack.
(b) Callee’s activities
(i) Saves registers values and other status information on the stack.
(ii) Sets the dynamic link.
(iii)Sets the base pointer (BP) of the new activation record and the top of the stack.
(iv) Makes space for the local names on the stack and begins execution.
- Return sequence.
(a) Callee’s activities
(i) Sets the base pointer to the activation record of the calling procedure and also sets the top of the stack.
(ii) Restore registers.
(iii) Branches to the return address saved in the stack and return to the caller.
(b) Caller’s activities
(i) Restore stack pointer to the location containing the return value.
(ii) Use the returned value to evaluate an expression if required
- What is Schema Markup and what is its impact on SEO | Schema markup benefits | Role of schema in SEO
- Compare SLR, CLR, and LALR parsers.
- Top 10 Best Motivational Speakers in India 2021
- Syntax Directed Translation & intermediate code generation
- What are the basic aspects of storage management? Discuss them in brief?