Main issues will be discussed in more detail in the chapter For each environment, the language features and their properties Scoping and allocation issues; 2) Nature of procedure calls, B)Parameter passing mechanisms Focus on the general structure of the environment Note The compiler can only maintain an environment only indirectly It must generate code to perform the necessary maintenance operations during program execution
• Main issues will be discussed in more detail in the chapter: – For each environment, the language features and their properties (1) Scoping and allocation issues; (2) Nature of procedure calls; (3) Parameter passing mechanisms • Focus on the general structure of the environment • Note: – The compiler can only maintain an environment only indirectly – It must generate code to perform the necessary maintenance operations during program execution
7.1 Memory Organization During Program Execution
7.1 Memory Organization During Program Execution
The memory of a typical computer A register area Addressable Random access memory(ram) A code area a data area The code area is fixed prior to execution, and can be visualized as olle LOWS Entry pointer to procedure Code for procedure Entry pointer to procedure2 Code for procedure 2 Entry pointer to procedure n Code for procedure n In particular, the entry point for each procedure and function is known at compile time
The memory of a typical computer: A register area; Addressable Random access memory (RAM): A code area; A data area. The code area is fixed prior to execution, and can be visualized as follows: Entry pointer to procedure1→ Code for procedure 1 Entry pointer to procedure2→ Code for procedure 2 … Entry pointer to procedure n→ Code for procedure n In particular, the entry point for each procedure and function is known at compile time
The global and/or static data of a program can be fixed in memory prior to execution Data are allocated separately in a fixed area in a similar fashion to the code In Fortran 77.all data are in this class In Pascal, global variables are in this class In c. the external and static variables are in this class The constants are usually allocated memory in the global/static area Const declarations of c and pascal Literal values used in the code such as"Hello%Dn"and Integer value 12345 Printf(“Hllo%dn”,12345)
• The global and/or static data of a program can be fixed in memory prior to execution – Data are allocated separately in a fixed area in a similar fashion to the code • In Fortran77, all data are in this class; • In Pascal, global variables are in this class; • In C, the external and static variables are in this class • The constants are usually allocated memory in the global/static area – Const declarations of C and Pascal; – Literal values used in the code, • such as “Hello%D\n ” and Integer value 12345: • Printf(“Hello %d\n ”,12345);
The memory area used for dynamic data can be organized in many different ways Typically, this memory can be divided into a stack area and a heap area a stack area used for data whose allocation occurs in fifo fashion a heap area used for dynamic allocation occurs not in Fifo fashion Generally, the architecture of the target machine includes a processor stack for procedure calls and returns Sometimes, a compiler will have to arrange for the explicit allocation of the processor stack in an appropriate place in memory
• The memory area used for dynamic data can be organized in many different ways – Typically, this memory can be divided into a stack area and a heap area; • A stack area used for data whose allocation occurs in FIFO fashion; • A heap area used for dynamic allocation occurs not in FIFO fashion. • Generally, the architecture of the target machine includes a processor stack for procedure calls and returns. – Sometimes, a compiler will have to arrange for the explicit allocation of the processor stack in an appropriate place in memory