Lecture 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

WELCOME TO THE

FUNDAMENTALS OF
PROGRAMMING
University of Kelaniya
Sri Lanka

Fundamentals of Programming
COSC / COST 11023

INTRODUCTION

SACHINTHA PITIGALA
piti@kln.ac.lk

© 2022 - Sachintha Pitigala


What is this Class?

< 3 >
Introduction to the art of
Programming

< 4 >
< 5 >
New to Programming?

1. PRACTICE

2. PRACTICE

3. PRACTICE

Can’t Passively Absorb Programming as a Skill

< 6 >
What are the uses of
Computers?

< 7 >
Computers allow us to do:

< 8 >
Computers allow us to do:

< 9 >
Computers allow us to do:

< 10 >
Computers allow us to do:

< 11 >
Computers allow us to do:

< 12 >
Computers allow us to do:

< 13 >
Computers allow us to do:

< 14 >
Computers allow us to do:

< 15 >
So… What is a Computer?

< 16 >
Is it a Magical Device?

< 17 >
What is a Computer?
•Computer is a programmable electronic
device that can store, retrieve, and
process data.

< 18 >
Memory Organisation of a Computer
• Computer is an electronic device.

• It can understand only electric current is on and off


states.

• Two circuit states correspond to 0 and 1.

• Bit (Binary Digit) refers to a single 0 or 1.

• Bit patterns represent both the computer instructions


and data.

< 19 >

How Does Computer Represent Letters?

65 - 54 53
A - 65

American
Standard Code
for Information
Interchange
(ASCII) <20 >

In the Beginning…..

< 21 >
Now…

< 22 >
Human vs Computer
• Univeristy of Kelaniya

< 23 >
Computers are not intelligent

< 24 >
< 25 >
But….
• Computers be able to:
• Performs calculations accurately
• Performs calculations quickly
• Remembers information (results)

12 + 3 + 5 + 8 + 9 + 9 + 2 + 4 + 11 + 3 + 7 + 7 + 8 + 9 + 3

< 26 >

How to Tell a Computer to What to Do?

< 27 >
< 28 >
What is a Computer Program?
•A sequence of instructions to be provided
to a computer to solve a problem.

< 29 >
What is a Computer Programming?
•It is the process of planning and writing a
sequence of steps (called instructions) for
computer to follow .

STEP 1

STEP 2

STEP 3
. . .

< 30 >
How we can communicate with
computers?

Using a Language

< 31 >
What is Programming Language?

•A programming language de nes a set of


rules, symbols, and special words used to
construct a computer program.

< 32 >
fi
Examples

< 33 >
Types of Programming Languages

•Machine Language

•Assembly Languages

•High-Level Languages

< 34 >

Machine Language

• Machine Language is made up of binary-coded


instructions (0s and 1s), that is used directly by the
computer.

• This is the only programming language computers can


understand.

< 35 >

Machine Language

• For Example,
cost=price+tax

• In machine code could look like this:

0010 0000 0000 0100


0100 0000 0000 0101
0011 0000 0000 0110
0101 0000 0010 0110

< 36 >

Machine Language

Advantages Disadvantages

Fast Execution Very hard to implement

Speci c to computer
Ef cient use of memory
architecture (not portable)

< 37 >
fi
fi
Assembly Languages

• Assembly Language is a low-level programming


language in which a mnemonic is used to represent each
of the machine language instructions for a particular
computer.

• A programming upgrade from machine language.

< 38 >

Assembly Languages
• For Example,
cost=price+tax

• In assembly language code could look like this:

ADD R2, R3
MOV R1

• However, computer cannot directly execute the assembly


language code.
< 39 >

Assembly Languages
0010 0000 0000 0100
ADD R2, R3 0100 0000 0000 0101
MOV R1 0011 0000 0000 0110
0101 0000 0010 0110

Assembly Code Assembler Machine Code

• Assembler a program that translates an assembly


language program into machine code.

< 40 >

Assembly Language

Advantages Disadvantages

Easier write program than the Need assembler to


machine language translation

Speci c to computer
Ef cient use of memory
architecture (not portable)

< 41 >
fi
fi
High Level Languages

• High Level Languages are


closer to English and other
natural languages.

< 42 >
High Level Languages

0010 0000 0000 0100


0100 0000 0000 0101
0011 0000 0000 0110
0101 0000 0010 0110

< 43 >

High Level Languages


0010 0000
0000 0100
0100 0000
0000 0101
Translator
0011 0000
0000 0110
0101 0000
Compilation Interpretation 0010 0110

HLL Code Compiler Interpreter Machine Code

Source Code Object Code

< 44 >

High-Level Languages

• Compiler translates the entire program into a machine


language before executing any of the instructions.

• Interpreter on the other hand translates and then


executes single instruction or group of instructions at a
time.

< 45 >

High-Level Languages

• The original HLL code is called the source code.

• The compiled code is called the object code.

Source Code Object Code

Translator Machine-
High-level Compiler language
Language Program

< 46 >

Source Code vs Object Code

Source Code Object Code

Consists of binary numbers


Form of Text
(0s and 1s)

Human Readable Machine Readable

Generated by Human / Input


Generated by the Compiler
for the compiler

< 47 >
High Level Languages

Advantages Disadvantages

Easier write programs Slower


Needs less programming
Needs more resources
time
Protable

< 48 >

You might also like