You are on page 1of 36

Department of Department of CS and IT

School of Computing and Mathematics

BCSC 1102 Introduction to Programming

Dr. Shem Mbandu Angolo, Ph.D.


asmbandu@cuk.ac.ke

Sept-Dec 2019
1/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1
Outline

1 Introduction

2 Compiling Programs

2/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


INTRODUCTION I

• C is a high level language.


• In 1970 a programmer, Dennis Ritchie, created a new language
called C.
• The name came about because it superceded the old
programming language he was using: B.
• C was designed with one goal in mind: writing operating
systems.
• The language was extremely simple and flexible, and soon was
used for many different types of programs.
• When computers were first developed, the only way they could
be programmed was in terms of binary numbers that
corresponded directly to specific machine instructions and
locations in the computer’s memory.

3/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


INTRODUCTION II
• The next technological software advance occurred in the
development of assembly languages, which enabled the
programmer to work with the machine on a slightly higher level.
• A special program, known as an assembler, translates the
assembly language program from its symbolic format into the
specific machine instructions of the computer system.
• Because a one-to-one correspondence still exists between each
assembly language statement and a specific machine instruction,
assembly languages are regarded as lowlevel languages.
• The programmer must still learn the instruction set of the
particular computer system to write a program in assembly
language, and the resulting program is not portable; that is, the
program will not run on a different processor type without being
rewritten.

4/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


INTRODUCTION III
• The resulting program is not portable; that is, the program will
not run on a different processor type without being rewritten.
• This is because different processor types have different
instruction sets, and because assembly language programs are
written in terms of these instruction sets, they are machine
dependent.
• Then, along came the so-called higher-level languages, of which
the FORTRAN (FORmula TRANslation) language was one of
the first.
• To support a higher-level language, a special computer program
must be developed that translates the statements of the program
developed in the higher-level language into a form that the
computer can understand—in other words, into the particular
instructions of the computer.
• Such a program is known as a compiler.
5/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1
COMPILING PROGRAMS

• The program that is to be compiled is first typed into a file on the


computer system.

6/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The program that is to be compiled is first typed into a file on the


computer system.
• C programs can typically be given any name provided the last
two characters are “.c”

6/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The program that is to be compiled is first typed into a file on the


computer system.
• C programs can typically be given any name provided the last
two characters are “.c”
• A text editor is usually used to enter the C program into a file.

6/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The program that is to be compiled is first typed into a file on the


computer system.
• C programs can typically be given any name provided the last
two characters are “.c”
• A text editor is usually used to enter the C program into a file.
• The program that is entered into the file is known as the source
code because it represents the original form of the program
expressed in the C language.

6/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The program that is to be compiled is first typed into a file on the


computer system.
• C programs can typically be given any name provided the last
two characters are “.c”
• A text editor is usually used to enter the C program into a file.
• The program that is entered into the file is known as the source
code because it represents the original form of the program
expressed in the C language.
• After the source program has been entered into a file, you can
then proceed to have it compiled.

6/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The program that is to be compiled is first typed into a file on the


computer system.
• C programs can typically be given any name provided the last
two characters are “.c”
• A text editor is usually used to enter the C program into a file.
• The program that is entered into the file is known as the source
code because it represents the original form of the program
expressed in the C language.
• After the source program has been entered into a file, you can
then proceed to have it compiled.
• The compilation process is initiated by typing a special
command on the system.

6/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The program that is to be compiled is first typed into a file on the


computer system.
• C programs can typically be given any name provided the last
two characters are “.c”
• A text editor is usually used to enter the C program into a file.
• The program that is entered into the file is known as the source
code because it represents the original form of the program
expressed in the C language.
• After the source program has been entered into a file, you can
then proceed to have it compiled.
• The compilation process is initiated by typing a special
command on the system.
• When this command is entered, the name of the file that contains
the source program must also be specified.
6/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1
COMPILING PROGRAMS

• For example, under Unix, the command to initiate program


compilation is called cc. If you are using the popular GNU C
compiler, the command you use is gcc.Typing the line

7/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• For example, under Unix, the command to initiate program


compilation is called cc. If you are using the popular GNU C
compiler, the command you use is gcc.Typing the line
• has the effect of initiating the compilation process with the
source program contained in prog1.c

7/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• For example, under Unix, the command to initiate program


compilation is called cc. If you are using the popular GNU C
compiler, the command you use is gcc.Typing the line
• has the effect of initiating the compilation process with the
source program contained in prog1.c
• In the first step of the compilation process, the compiler
examines each program statement contained in the source
program and checks it to ensure that it conforms to the syntax
and semantics of the language.

7/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• For example, under Unix, the command to initiate program


compilation is called cc. If you are using the popular GNU C
compiler, the command you use is gcc.Typing the line
• has the effect of initiating the compilation process with the
source program contained in prog1.c
• In the first step of the compilation process, the compiler
examines each program statement contained in the source
program and checks it to ensure that it conforms to the syntax
and semantics of the language.
• If any mistakes are discovered by the compiler during this phase,
they are reported to the user and the compilation process ends
right there.

7/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The errors then have to be corrected in the source program (with


the use of an editor)

8/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The errors then have to be corrected in the source program (with


the use of an editor)
• the compilation process must be restarted.Typical errors reported
during this phase of compilation might be due to an expression
that has unbalanced parentheses (syntactic error), or due to the
use of a variable that is not “defined” (semantic error).

8/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The errors then have to be corrected in the source program (with


the use of an editor)
• the compilation process must be restarted.Typical errors reported
during this phase of compilation might be due to an expression
that has unbalanced parentheses (syntactic error), or due to the
use of a variable that is not “defined” (semantic error).
• After the program has been translated into an equivalent
assembly language program, the next step in the compilation
process is to translate the assembly language statements into
actual machine instructions.

8/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The errors then have to be corrected in the source program (with


the use of an editor)
• the compilation process must be restarted.Typical errors reported
during this phase of compilation might be due to an expression
that has unbalanced parentheses (syntactic error), or due to the
use of a variable that is not “defined” (semantic error).
• After the program has been translated into an equivalent
assembly language program, the next step in the compilation
process is to translate the assembly language statements into
actual machine instructions.
• This step might or might not involve the execution of a separate
program known as an assembler. On most systems, the assembler
is executed automatically as part of the compilation process.

8/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The assembler takes each assembly language statement and


converts it into a binary format known as object code, which is
then written into another file on the system.This file typically has
the same name as the source file under Unix, with the last letter
an “o” (for object) instead of a “c”. Under Windows, the suffix
letters "obj" typically replace the “c” in the filename.

9/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The assembler takes each assembly language statement and


converts it into a binary format known as object code, which is
then written into another file on the system.This file typically has
the same name as the source file under Unix, with the last letter
an “o” (for object) instead of a “c”. Under Windows, the suffix
letters "obj" typically replace the “c” in the filename.
• After the program has been translated into object code, it is ready
to be linked. This process is once again performed automatically
whenever the cc or gcc command is issued under Unix.The
purpose of the linking phase is to get the program into a final
form for execution on the computer. If the program uses other
programs that were previously processed by the compiler, then
during this phase the programs are linked together. Programs
that are used from the system’s program library are also searched
and linked together with the object program during this phase.
9/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1
COMPILING PROGRAMS

• The process of compiling and linking a program is often called


building.

10/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The process of compiling and linking a program is often called


building.
• The final linked file, which is in an executable object code
format, is stored in another file on the system, ready to be run or
executed. Under Unix, this file is called a.out by default. Under
Windows, the executable file usually has the same name as the
source file, with the c extension replaced by an exe extension.

10/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The process of compiling and linking a program is often called


building.
• The final linked file, which is in an executable object code
format, is stored in another file on the system, ready to be run or
executed. Under Unix, this file is called a.out by default. Under
Windows, the executable file usually has the same name as the
source file, with the c extension replaced by an exe extension.
• When the program is executed, each of the statements of the
program is sequentially executed in turn.

10/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• The process of compiling and linking a program is often called


building.
• The final linked file, which is in an executable object code
format, is stored in another file on the system, ready to be run or
executed. Under Unix, this file is called a.out by default. Under
Windows, the executable file usually has the same name as the
source file, with the c extension replaced by an exe extension.
• When the program is executed, each of the statements of the
program is sequentially executed in turn.
• If the program requests any data from the user, known as input,
the program temporarily suspends its execution so that the input
can be entered.

10/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• Or, the program might simply wait for an event, such as a mouse
being clicked, to occur.

11/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• Or, the program might simply wait for an event, such as a mouse
being clicked, to occur.
• Results that are displayed by the program, known as output,
appear in a window, sometimes called the console.

11/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• Or, the program might simply wait for an event, such as a mouse
being clicked, to occur.
• Results that are displayed by the program, known as output,
appear in a window, sometimes called the console.
• Or, the output might be directly written to a file on the system.

11/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• Or, the program might simply wait for an event, such as a mouse
being clicked, to occur.
• Results that are displayed by the program, known as output,
appear in a window, sometimes called the console.
• Or, the output might be directly written to a file on the system.
• If all goes well (and it probably won’t the first time the program
is executed), the program performs its intended functions.

11/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• Or, the program might simply wait for an event, such as a mouse
being clicked, to occur.
• Results that are displayed by the program, known as output,
appear in a window, sometimes called the console.
• Or, the output might be directly written to a file on the system.
• If all goes well (and it probably won’t the first time the program
is executed), the program performs its intended functions.
• If the program does not produce the desired results, it is
necessary to go back and reanalyze the program’s logic.

11/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• Or, the program might simply wait for an event, such as a mouse
being clicked, to occur.
• Results that are displayed by the program, known as output,
appear in a window, sometimes called the console.
• Or, the output might be directly written to a file on the system.
• If all goes well (and it probably won’t the first time the program
is executed), the program performs its intended functions.
• If the program does not produce the desired results, it is
necessary to go back and reanalyze the program’s logic.
• This is known as the debugging phase, during which an attempt
is made to remove all the known problems or bugs from the
program

11/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

• To do this, it will most likely be necessary to make changes to the


original source program. In that case, the entire process of
compiling, linking, and executing the program must be repeated
until the desired results are obtained.

12/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


COMPILING PROGRAMS

13/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1


Bibliography

14/14 Dr. Shem Mbandu Angolo, Ph.D. BCSC 1102 Lecture 1

You might also like