Title: Chapter 1: Introduction
1- Chapter 1 Introduction
- What is a program ?
- A program is a sequence of instructions written
according to a vocabulary and a set of
grammatical rules and which are meant to be
executed by the machine (PC) - So to write a program in in a given programming
language you should know - The vocabulary of that language
- The grammar rules of that language
- You should also be aware that
- program is intended to be executed by a machine
and not by a human. So the vocabulary and the
rules should be strictly respected.
2A Simple Template of C program
void main ( )
The instructions of the program should be put
between the two braces. This part, delimited by
the two braces is called the Body of the program
3A simple program Addition of two numbers
You declare three variables, these variable are
of type int, means they are integers. You call
them Num1, Num2 and Sum.
void main ( ) int Num1 int Num2 int Sum
Num1 2 Num2 4 Sum Num1 Num2
Num1 and Num2 represent the numbers to be added,
and Sum represents their sum
You assign the value 2 to Num1 and 4 to Num2
You assign the sum of Num1 and Num2 to Sum
4How the program and the instructions are
presented inside the machine ? And how the
execution is performed by the computer ? What is
inside the Machine ?
CPU Central Processing Unit, e.g. Pentium III ,
is in charge of executing the program
instructions Memory contains the program to be
executed
5How does it work ? In the Memory,The program
instructions are stored as a sequence of binary
code
The CPU reads the 1st instruction decodes
it executes it moves to the following
instruction reads it decodes it executes
it Until the end of the program
Memory
6The Compiler and the Linker
It is quite a complicated task to write a
program in a binary code. To read such code is
further more complicated
Sine the CPU understands only binary coded
instructions, there is a need to traduce the
instructions from the C language (or whatever
other language) to a binary coded version. Part
of this Job is done by the Compiler.
7- The compiler is itself a program that
- Check and detect errors in your program
- If your program is error-free than it translates
your source code into and object code. - .
The object code is similar to the machine code
but it is not executable.
8The linker
Object code
00110011 11001001 10101000
Linker
Machine code
00001100 00110011 11001001 10101000
The linker transforms the object code into an
executable machine code.
9int Num Num 10 printf(d, Num)
When necessary, the linker combines other object
codes, to form the executable program. It is the
case when the source code uses pieces of code
defined in other source code programs. In the
piece of code above, the prinf instruction which
prints the value of Num on the screen, is defined
in another source code elsewhere, the linker
combines the related object code with the main
object code to produce a single executable
program.
10- The Integrated development environment
- So far we have seen that to develop a program you
need to - Edit the program
- writing a piece of text containing your
programs instructions - Compile the program
- Link the program
- You can do these tasks yourself, e.g. editing
your program with Word editor, than you run the
compiler to check and compile your program, then
afterwards call the linker to generate an
executable version of your program that you can
run.
But a more practical alternative would be to use
an Integrated development environment
11- An Integrated development environment is an
interactive framework software that allows you
to - Edit your program using his own editor
- Compile your program it reports and describes
your errors and support you to correct your
program - Link and run your program
- It performs also other useful task such that
- Saving your program in the floppy or hard disc
- Debugging your program Executing the program
instruction by instruction
Examples of Integrated environment development
Microsoft Visual C Borland Turbo
C, Turbo C (will be used in Lab sessions)
12The computer system architecture The minimum
computing system is it sufficient to develop a
program ?
- No
- we need devices
- to write the program
- to enter the instructions,
- to save the program
- to display the output of the program
- These tasks need three types of devices
- Input devices systems through which data and
instructions enter the CPU/Memory - Output devices systems through which you
display data coming from the CPU/Memory - Input/output devices used usually to save and
store data/programs
13A complete computer system
CPU the heart of the computer, executes the
instructions
Memory where data and programs are stored
Input devices usually a
keyboard and mouse, Output devices A
monitor, a printer, Output/Input devices
Hard/floppy disk, CD-ROM,
14The Operating system The functioning of the
different of the the computer systems is
controlled by a program called the operating
system. It is this program that recognizes
that a key was typed in the keyboard, a mouse
button was pressed, sends output to the screen,
etc. It ensures also the coordination between
the different computer components, for instance
the CPU can not simultaneously read instructions
from the memory and store data in the hard disk.
The operating system is the most important
program that runs on the computer , it is located
in the memory are and can never be
changed. Examples of Operating System DOS WINDOWS
LINUX UNIX
15File and Directory A program (or whatever
information) can be stored (saved) , in an
input/output device such as Hard disk, floppy
disk, etc. The place where the program is saved
is called a file A Directory (Called Folder in
Windows) is a location area in the hard/floppy
disc that contains 0 or more, files/directories F
iles and directories are defined by their
names Directories are organized into hierarchical
structure
game2