Copyright © 2023 by
Rance D. Necaise
|
|
3.2 Program TranslationThe instructions in an assembly language program must be translated into the bit patterns of the underlying machine code instructions. This translation is done using an assembler. ![]() Assembly languages typically allow labels to be used before they have been defined, unlike high-level programming languages. Thus, the translation process requires two passes
The assembler produces object code or a file called an object file. This file contains the machine instructions, data and bookkeeping information. An object file can not be executed because it may reference routines or data in other files that have not yet been assembled. This is known as an unresolved reference. An object file on UNIX systems contain six distinct sections ![]() The object file header describes the size and position of the other parts since those can vary depending on the contents of the source file. The text segment contains the machine language code for functions in the source file. This part may not be complete if functions defined outside of the module are called. In that case, there will be unresolved references to those functions. The data segment contains a binary representation of the global data defined in the source file. This part is not a complete data segment for the program, but only for the given module. The relocation information identifies instructions and data that depend on absolute addresses. These must be changed or relocated to reflect their true locations when the complete program is constructed. The symbol table part contains a list of labels used in the source file along with their corresponding addresses. This information is used to resolve addresses within the given module and other modules when the final program is constructed. Finally, the debugging information part contains information that can be used by a debugger, which can be used by a programmer to debug large programs. The assembler must translate each file or module in a program separately. During this process, it can only determine the addresses of the local labels, those used within the file itself. A second program called a linker is used to combine the collection of object files into an executable file. In doing so, it resolves the addresses of labels that are referred to in other object files. This is known as resolving external references. ![]() The use of a linker allows a program to be split into pieces that are stored in different files. Each file contains a logically related collection of subroutines and data structures that form a module in a larger program.
|