Chapter 1: Introduction: in This Chapter You Will Learn About
Chapter 1: Introduction: in This Chapter You Will Learn About
Chapter 1: Introduction
In this chapter you will learn about:
Overview of Computer Component
Overview of Programming
The different types of language
Natural Language
Formal Language
Functional / Imperative Language
Programming Languages
NI S2 2009/10
1
Principles of Programming
2
Principles of Programming
Ordered sequence
of storage location
(memory cell)
Components of a PC
3
Principles of Programming
4
Principles of Programming
What is Programming?
Programming is instructing a computer to do
something for you with the help of a Programming
Language
A programming language contains instructions for the
computer to perform a specific action or a specific
task:
Display “I like programming”
Display the current time
5
Principles of Programming
6
Principles of Programming
7
Principles of Programming
8
Principles of Programming
Programming Language
The two roles of a programming language:
Technical: It instructs the computer to perform tasks.
Conceptual: It is a framework within which we organize our
ideas about things and processes.
In programming, we deal with two kind of things:
Data - representing 'objects' we want to manipulate
Procedures -'descriptions' or 'rules' that define how to
manipulate data.
9
Principles of Programming
Programming Language
Can be classified into a special-purpose and general-
purpose programming languages.
Special-purpose : is designed for a particular type of
application
Structured Query Language (SQL)
General-purpose : can be used to obtain solutions for
many types of problems.
Machine Languages
Assembly Languages
High-Level Languages
10
Principles of Programming
Machine Language
The only language that the processor actually
'understands‘
Consists of binary codes: 0 and 1
Example: 00010101
11010001
01001100
Each of the lines above corresponds to a specific task to
be done by the processor.
Programming in machine code is difficult and slow since it
is difficult to memorize all the instructions.
Mistakes can happen very easily.
Processor and Architecture dependent (different machine
language for different type of CPU) – not portable.
11
Principles of Programming
Assembly Language
Enables machine code to be represented in words and
numbers.
Example of a program in assembly language:
LOAD A, 9999
LOAD A, 9999 LOAD A,0111001100
9999
LOAD B, 8282 LOAD B, 8282
SUB B
LOAD
B
B, 8282
1000110011
Assembler
SUB 1001111001
SUB B MOV C, A MOV C, 1100110010
A
MOV C, A
Easier to understand and memorize (called Mnemonics),
compared to machine code but still quite difficult to use.
Cannot be processed directly by a computer, must be
converted to machine language using assemblers.
Processor and Architecture dependent – not portable.
12
Principles of Programming
High-Level Language
13
Principles of Programming
14
Principles of Programming
15
Principles of Programming
C Programming Language
Why 'C' ?
Because based on 'B'; developed at Bell Laboratories
17
Principles of Programming
C – An Imperative Language
C is a highly imperative formal language
We must tell it exactly how to do what;
the means and functions to use;
which libraries to use;
when to add a new line;
when an instruction is finished;
in short: everything and anything…
filename.c
18
Principles of Programming
19
Principles of Programming
A Simple Program in C
#include <stdio.h>
int main(void)
{
printf("I like programming in C.\n");
return (0);
}
20
Principles of Programming
int main(void)
Start of Segment
{
Function for printing text
}
End of Segment
21
Principles of Programming
C Output
I like programming in C.
22
Principles of Programming
Summary
23