Page 168 - DCAP507_SYSTEM_SOFTWARE
P. 168

System Software




                    Notes
                                          Example: We expand on Example 1 so that every routine has a text, data, and bss segment.
                                   The word alignment remains 4 bytes, but the page size is 0x1000 bytes. l r r r. name text data bss
                                   _ main 1017 320 50 calif 920 217 100 mass 615 300 840 newyork 1390 1213 1400 (all numbers hex)
                                   The linker first lays out the text, then the data, then the bss. Observe that the data section begins
                                   on a page boundary at 0x5000, but the bss starts immediately after the data, since at run time data
                                   and bss are rationally one segment. l r r r. name text data bss _ main 1000 - 2016 5000 - 531f 695c
                                   - 69ab calif 2018 - 2937 5320 - 5446 69ac - 6aab mass 2938 - 2f4c 5448 - 5747 6aac - 72eb newyork 2f50
                                   - 42df 5748 - 695a 72ec - 86eb There's wasted space at the end of the page between 42e0 and 5000.
                                   The bss segment ends in mid-page at 86eb, but usually programs assign heap space beginning
                                   instantly after that.

                                   Self Assessment


                                   Fill in the blanks:
                                   10.  Most of the symbols defined in a .............................. object file are defined comparative to
                                       storage regions inside the file, so the symbols cannot be resolved until the areas addresses
                                       are recognized.
                                   11.  Each .............................. file utilizes a model of the target address space.
                                   12.  The fundamental concern in a .............................. linker or loader is to make sure that all the
                                       sections in a program are defined and have addresses, but that addresses don't overlie
                                       where they're not supposed to.

                                   10.6 Variable


                                   It is an identifier, which refers to computer memory space where some value can be stored.
                                   A variable can have different values at different stages of the program execution.
                                   All variables must be declared before their use in a program. You may wonder why variables
                                   must be declared before use. There are two reasons:
                                   It makes things somewhat easier on the compiler, it knows right away what kind of storage to
                                   allocate and what code to emit to store and manipulate each variable; it doesn't have to try to
                                   intuit the programmer's  intentions.
                                   It forces a bit of useful discipline on the programmer: you cannot introduce variables willy-
                                   nilly; you must think about them enough to pick appropriate types for them. (The compiler's
                                   error messages to you, telling you that you apparently forgot to declare a variable, are as often
                                   helpful as they are a nuisance: they're helpful when they tell you that you misspelled a variable,
                                   or forgot to think about exactly how you were going to use it.)

                                   The syntax and examples of variable declaration are:


                                          Example:
                                          int real;
                                          char choice;
                                   A declaration for a variable can also contain an initial value. This initializer consists of an equals
                                   sign and an expression, which is usually a single constant:
                                        int i = 1;
                                        int i1 = 10, i2 = 20;


          162                               LOVELY PROFESSIONAL UNIVERSITY
   163   164   165   166   167   168   169   170   171   172   173