انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة
الكلية كلية تكنولوجيا المعلومات
القسم قسم البرامجيات
المرحلة 3
أستاذ المادة نداء عبد المحسن عباس العطوان
24/03/2019 08:55:32
Run Time Environments Before we get into the low-level details of final code generation, we first take a look at the layout of memory and the runtime data structures for managing the stack and heap.
Data Representation Simple variables: are usually represented by sufficiently large memory locations to hold them: • characters: 1 or 2 bytes • integers: 2, 4 or 8 bytes • floats: 4 to 16 bytes • Boolean: 1 bit (most often at least 1 full byte used)
During execution, allocation must be maintained by the generated code that is compatible with the scope and lifetime rules of the language. Typically there are three choices for allocating variables and parameters:
– Assign them fixed locations in global memory (“static” allocation). – Put them on the processor stack. – Allocate them dynamically in memory managed by the program (the “heap”).
Issues in Storage Organization • Recursion • Block structure and nesting (nested procedures). • Parameter passing (by value, reference, name). • Higher order procedures (procedures as parameters to other procedures). • Dynamic Storage Management (malloc, free).
Storage Organization From the perspective of the compiler writer, the executing target program runs in its own logical address space in which each program value has a location. The management and organization of this logical address space is shared between the compiler, operating system, and target machine. The operating system maps the logical addresses into physical addresses, which are usually spread throughout memory.
Compiler-writer Perspective
The run-time representation of an object program in the logical address space consists of data and program areas as shown in figure below. A compiler for a language like C++ on an operating system like Linux might subdivide memory in this way.
Storage for code and data:
Code Area: Procedures, functions and methods Static Data Area: “Permanent” data with statically known size. Stack: Temporary Data with known lifetime (lifetime refers to the different periods of time for which a variable remains in existence) Heap: Temporary Data with unknown lifetime (dynamically allocated). We assume the run-time storage comes in blocks of contiguous bytes, where a byte is the smallest unit of addressable memory. A byte is eight bit and four bytes form a machine word. Multi byte objects are stored in consecutive bytes and given the address of the first byte.
As discussed previously, the amount of storage needed for a name is determined from its type. An elementary data type, such as a character, integer, or float, can be stored in an integral number of bytes. Storage for an aggregate type, such as an array or structure, must be large enough to hold all its components.
The storage layout for data objects is strongly influenced by the addressing constraints of the target machine. On many machines, instructions to add integers may expect integers to be aligned, that is, placed at an address divisible by 4. Although an array of ten characters needs only enough bytes to hold ten characters, a compiler may allocate 12 bytes to get the proper alignment, leaving 2 bytes unused. Space left unused due to alignment considerations is referred to as padding. When space is at a premium, a compiler may pack data so that no padding is left; additional instructions may then need to be executed at run time to position packed data so that it can be operated on as if it were properly aligned.
المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
|