Compilation scheme assigns storage locations to all the programmer-defined variables. The storage locations are within the object program because of the processed declarations. Fixed address within the program is assigned to the temporary variables. These are such variables which include such variables which are used for saving the return address. Storage assignment is termed as the static allocation of memory. The languages which do not allow procedure with the help of the subroutines use the static allocation of memory. The type of languages which do not provide dynamic allocation for the storage process during its execution. If you want to have the next level understanding of the concept, then you must give a read to the features of the machine-dependent compilers.
When there is a recursive call of the procedures, then there cannot be any usage of the static allocation. The loader or the operating system calls the MAIN program, and MAIN does the first action of the storage of the return address from a register at a fixed position to another location in the memory. If we take an example where we need to perform subtraction, then MAIN calls the procedure SUB. A fixed location in SUB stores the return address of the call. If there is any recursive call of the procedure SUB, then the problem arises. Then the correct usage of them is not possible, and this destroys the return address. Then the possibility of the correct return by MAIN diminishes.
When SUB uses another variable, it faces the same difficulty. The variables within SUB variables describe the same difficulty. The new variables SUB when going through the recursive call then the provided contents of the variables are destroyed. After returning from the recursive call, they need to have invocation 2 of SUB.
What is necessary?
The values used previously in the variables used by SUB are essential for the smooth functioning and processing. These include return addresses, parameters, register save areas and many more every time any recursive call has been made. The dynamic storage allocation technique is the source of the accomplishment. An activation record gets created on the procedure call. These consists of the variables and storage used by the procedure. When there is more than one recursive call, then there is the creation of the activation record. The procedure and the activation record are not associated directly. A particular invocation of the procedure is connected and associated with the procedure. There is no deletion of the activation record until the return has been made from the corresponding invocation. There is a base register in the starting address of the current activation record. The registers are used for the procedure of the variables’ addresses. Different invocations of a procedure use the variables, and the va
lues keep separate from each other.
Stacks are used for the allocation of the activation record. The current record is at the top of the stack. The procedure calls MAIN. To set the indication in the starting address of the current activation address another register is used. Containing the first word in an activation record is a pointer PREV. It is the previous record on the stack. The value in the pointer is null as it is the first record. Then there is the NEXT pointer in the second word. It takes to the first unused stack word. Then this turns out to the starting address for the next created activation record. In the third address, we have the return address for the procedure of invocation. In addition to this, there are the remaining words as well in the variables which the procedure uses.
When the caller gets its procedure, then there is the deletion of the current activation record. There is the reestablishment of the current one from the previously used activation record. The procedure of the execution continues. Even after the recursive call, the values of the address remain the same as they were before. This is the technique which is used for the automatic allocation of the storage. It is best used for distinguishing the types of the dynamic allocation. These are the procedures which are under the programmer’s control. There must be a generation of the codes for the reference purpose when there is automatic allocation.
Prologue and Epilogue
There is the addition of the generated code in the compiler. It is for the management of the activation record. At the time of the beginning of every procedure, the creation of the new activation record is a must. The name of the code used here is called prologue for the procedure. There must be the resetting deletion of the current activation record and the pointers.
When we use automatic allocation, the variables which the procedure used on being called get the value in the storage.
When the programs in some languages are divided into small units, then those units are termed as blocks. In other words, they are the important and the special portion of a program which hold the capability of declaring its identifiers. The units in other languages, such as PASCAL have also got the same definition. They are used in procedure and functions.
In a block-structured program, the terms block and procedures are used interchangeably. When doing the compilation of the program, it is better to number the blocks to be used. It makes the things easy and simple. You just have to recognize the beginning of a new block, and then the rest of the blocks get the sequential number. Hence, we see the beginning of the construction of the table which eases the process of the block structure. Nesting depth for each block is given to the block-level entry. The number 1 to the block is given to the outermost block, and the rest of the blocks are given the greater surrounding number.
We are allowed to use a name more than once in a program, and that is why the identifier’s symbol-table entry must have declared block’s number. It is legal to declare an identifier when that identifier has not been declared previously by the current block. This is why there can be multiple entries in the symbol-table with the same name. The chain of pointers is used for representing the entries of the same name by different blocks. The main function of performing this function is the linking of the symbol table with them.