Chapter 1 - 1.3

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

reasons why programmers need to understand how compilation systems work

1. Optimizing program performance 2. Understanding link-time errors 3. Avoiding security holes

computer system

A computer system consists of hardware and systems software that work together to run application programs.

fundamental idea

All information in a system-including disk files, programs stored in memory, user data stored in memory, and data transferred across a network - is represented as a bunch of bits.

Why is Assembly language useful?

Assembly language is useful because it provides a common output language for different compilers for different high-level languages. For example, C compilers and Fortran compilers both generate output files in the same assembly language.

text files

Files such as hello. c that consist exclusively of ASCII characters are known as text files.

binary files

Files such as hello. c that consist exclusively of ASCII characters are known as text files. All other files are known as binary files.

3. Assembly phase.

Next the assembler (as) translates hello.s into machine language instructions, packages them in a form known as a relocatable object program, and stores the result in the object file hello.o. This file is a binary file containing 17 bytes to encode the instructions for function main. If we were to view hello. o with a text editor, it would appear to be gibberish. .s → .o which is an object file; fragments of machine code with unresolved symbols, i.e., some addresses not yet known (vars/subrs).

4. Linking phase

Notice that our hello program calls the printf function, which is part of the standard C library provided by every C compiler. The printf function resides in a separate precompiled object file called printf.o, which must somehow be merged with our hello. o program. The linker (ld) handles this merging. The result is the hello file, which is an executable object file (or simply executable) that is ready to be loaded into memory and executed by the system. .o + library links → a.out (default name);resolves symbols, generates an executable

Compiler Driver

On a Unix system, the translation from source file to object file is performed by a compiler driver

source program (or source file)

Our hello program begins life as a source program (or source file). that the programmer creates with an editor and saves in a text file called hello. c. The source program is a sequence of bits; each with a value of 0 or 1, organized in 8,bit chunks called bytes. Each byte represents some text character in the program.

2. Compilation phase.

The compiler (eel) translates the text file hello. i into the text file hello. s, which contains an assembly-language program. .i → .s which is assembler source code

context

The only thing that distinguishes different data objects is the context in which we view them. For example, in different contexts, the same sequence of bytes might represent an integer, floating-point number, character string, or machine instruction.

1. Preprocessing phase.

The preprocessor ( cpp) modifies the original C program according to directives that beginning with the '#' character. For example, the #include <stdio .h> command in line 1 of hello. c tells the preprocessor to read the contents of the system header file stdio. h and insert it directly into the program text. The result is another C program, typically with the . i suffix. .c + .h = .i which is the ultimate source code - i.e., #includes expanded and #defines replaced

compilation system

The translation is performed in the sequence of four phases. The programs that perform the four phases (preprocessor, compiler, assembler, and linker) are known collectively as the compilation system.

the translation from source file to object file

The translation is performed in the sequence of four phases. The programs that perform the four phases (preprocessor, compiler, assembler, and linker) are known collectively as the compilation system.

low-level machine-language

in order to run hello. c on the system, the individual C statements must be translated by other programs into a sequence of low-level machine-language instructions. These instructions are then packaged in a form called an executable object program and stored as a binary disk file. Object programs are also referred to as executable object files.


Ensembles d'études connexes

Missed and Guessed Q's from Law of Promulgated Contracts

View Set

Property Casualty Exam - Quizzes

View Set

Chapter 4: Socioemotional Development in Infancy

View Set

Critical development geographies references

View Set

OSHA 30 - Module 1A: Introduction to OSHA and the OSH Act

View Set

Chapter 7: Management and Leadership

View Set

Carman Essentials of Pediatric Nursing 3rd Ed - Ch. 8 Atraumatic Care of Children and Families

View Set

Artificial Intelligence Chapter 12

View Set

Cells and their Organelles - Eukaryotic Cells

View Set