Vous êtes sur la page 1sur 25

Programming Environment

System Software
Program:
A program is a sequence of instructions written in a programming language that directs a computer in problem solving.

Software:
The software in a computer system consists of programs written to support the basic operations of the system and programs written to carry out an application.

Application software:
Application software consists of programs written to analyze data and solve specific problems.

System software:
Consists of a variety of programs that support the operation of a computer. This software makes it possible for the user to focus on an application or other problem to be solved, without needing to know the details of how the machine works internally Eg. Operating system, compiler, assembler, macro processor, loader or linker, debugger, text editor, database management systems (some of them) and, software engineering tools.

System Software
Operating System:
Overall manager of a computer system resources- allocating and deallocating memory, processor, devices, and files to a particular application program as they are needed.

Translator:
Compiler
A compiler is a program that accepts a program written in a high level language (source program) and produces its machine language equivalent (object program). Steps of Compilation: Lexical analysis The task of scanning the source program statement, recognizing, and classifying the various tokens is known as lexical analysis Tokens may be thought as the fundamental building blocks of the language. For example a token may be a keyword, a variable name, an integer, an arithmetic operator etc. Syntactic analysis After the token scan, each statement in the source program must be recognized as some language construct, such as a declaration or an assignment statement described by the grammar. This process is called syntactic analysis. Code generation The last step is generation of the machine language statement for each of the corresponding source language statement. Some compiler produces a symbolic program for later translation by an assembler

System Software
Translator:
Interpreter
Processes a source program written in a high-level language just like a compiler. The main difference is that interpreter converts each source program statement into an intermediate version and executes the operations specified by the source program statement. Usually performs lexical and syntactic analysis functions just like a compiler and then translate the source program statement into an intermediate form. Translation of the source program into an intermediate form is much faster than compiling it into the machine code. However, execution of the translated program is much slower than the execution of the machine code produced by a compiler.

System Software
Translator:
Assembler
An assembler is a program that translates a program written in assembly language to a machine language program.
Assembly code

Assembler Object code

System Software
Linker
A program that combines different object program along with the libraries routines into a single executable file which a computer can run.

Loader
A program that places programs into memory and progress them for execution.

Text Editor
A computer program that allows a user to create and revise a document such as computer program, text, tables, charts etc

Source Code to Execution

Text Editor
Unix/Linux editor : vi editor Starting vi editor:
Type vi or vi with a file name

Works in two modes:


Command mode Edit mode

Text Editor

Text Editor

Text Editor

Text Editor

C program structure
A C program normally have the following internal structure:
Preprocessor directives Global declarations Function definitions

/* * File: hello.c * ------------* This simple C program prints out the text "Hello world!". * * CS 535 Introduction to Scientific Computing * 29 January 2014 * */ #include<stdio.h> int main(void) { printf("Hello world!\n"); return 0; }

C program structure
C supports modular programming by allowing you to organize a program in as many source and header files as desired, and to edit and compile them separately.

circle.c

circulararea.c

Compilation Stages
There are 4 steps to obtain the final executable program, as shown:
Preprocessing stage : Removes the comments, process the preprocessor statements. Compiler stage: All C language code in the .c file is converted into a lower-level language called Assembly language; making .s files. Assembler stage: The assembly language code made by the previous stage is then converted into object code which are fragments of code which the computer understands directly. An object code file ends with .o. Linker stage: The final stage in compiling a program involves linking the object code to code libraries which contain certain "built-in" functions, such as printf. This stage produces an executable program, which is named a.out by default.

Different files in different stages


Source code files.:These files contain function definitions, and have names which end in ".c" by convention. Header files: These files contain function declarations (also known as function prototypes) and various preprocessor statements (see next slide). They are used to allow source code files to access externallydefined functions. Header files end in ".h" by convention. Assembly files : Contains the assembly language version of your preprocessed source code file. Object files:These files are produced as the output of the compiler. They consist of function definitions in binary form, but they are not executable by themselves. Object files end in ".o" by convention, although on some operating systems (e.g. Windows, MS-DOS), they often end in ".obj". Binary executables.:These are produced as the output of a program called a "linker". The linker links together a number of object files to produce a binary file which can be directly executed. Binary executables have no special suffix on Unix operating systems, although they generally end in ".exe" on Windows.

The preprocessor
Preprocessor commands start with the pound sign ("#"). There are several preprocessor commands. But two of the most important are:
#define. This is mainly used to define constants.
#define BIGNUM 10000

#include. This is used to access function definitions defined outside of a source code file.
#include <stdio.h> causes the preprocessor to paste the contents of <stdio.h> into the source code file at the location of the #include statement before it gets compiled. #include is almost always used to include header files, which are files which mainly contain function declarations and #define statements.

The preprocessor
The Preprocessor is in reality a separate program (normally called "cpp", for "C preprocessor"), but it is invoked automatically by the compiler before compilation proper begins. What the preprocessor does is convert the source code file you write into another source code file (you can think of it as a "modified" or "expanded" source code file). That modified file may exist as a real file in the file system, or it may only be stored in memory for a short time before being sent to the compiler. Either way, you don't have to worry about it, but you do have to know what the preprocessor commands do.

Commands for compilation


You can covert (compile) your source code file to its final executable format in two ways:
Using only one command: gcc/cc hello.c gcc/cc -o hello.c hello
This is feasible if your C language program is not very large and can be in one source file only. When the program becomes larger with different units, it is advisable, for better management to break it into separate source files and perform separate compilation.

Separate Compilation
Separate Compilation
The steps taken in creating the executable program can be divided up in to two compiler/assembler steps circled in red, and one final linker step circled in yellow. The two .o files may be created separately, but both are required at the last step to create the executable program. You can use the -c option with gcc/cc to create the corresponding object (.o) file from a .c file. For example, typing the command: gcc/cc -c green.c will not produce an a.out file, but the compiler will stop after the assembler stage, leaving you with a green.o file.

Separate Compilation
Separate Compilation
The three different tasks required to produce the executable program are as follows: Compile green.o: gcc/cc -c green.c Compile blue.o: gcc/cc -c blue.c Link the parts together: gcc/cc green.o blue.o For example, it is important to note that in order to create the file, green.o, the two files, green.c and the header file common.h are required. Similarly, in order to create the executable program, a.out, the object files green.o and blue.o are required.

Our First C Program


/* * File: hello.c * ------------* This simple C program prints out the text "Hello world!". * * CO 102 Computing Lab * 21 January 2013 * */ #include<stdio.h> int main(void) { printf("Hello world!\n"); return 0; }

Output from assembly stage

Vous aimerez peut-être aussi