View File

advertisement
Computer Programming I
Lecture 02
ENGR. SHOAIB ASLAM
Contents
 Computer Languages
 Machine Languages
 Algorithms
 Compiler
 Interpreter
 Assembler
Computer Languages
 What is a Language…?
 human beings communicate with each others in different
language such as Urdu, French, Punjabi and Arabic etc.
 to communicate with the computers we have to use
specific languages
 hundreds of languages have been develop in which few of
them has gained international reputation. C language
is one of them
Computer Languages
 TYPES
 Basically, languages are divided into two categories according to their
interpretation.
Low Level Languages
High Level Languages
Low Level Languages
 Low level computer languages are machine codes or
close to it.
 Computer cannot understand instructions given in
high level languages or in English.
 It can only understand and execute instructions
given in the form of machine language i.e. language
of 0 and 1. There are two types of low level
languages:


Machine Language
Assembly Language
Low Level Languages
 Machine Language
 Lowest and most elementary level of Programming




language
First type of programming language to be Developed.
It is basically the only language which computer Can
understand. In fact, a manufacturer designs a computer
to obey just one Language, its machine code, which is
represented inside the computer by a String of binary
digits (bits) 0 and 1.
The symbol 0 stands for the absence of Electric pulse
and 1 for the presence of an electric pulse .
Since a computer is Capable of recognizing electric
signals, therefore, it understand machine Language.
Low Level Languages
 Assembly Language
 Also low level but a very important language in which
operation codes and operands are given in the form of
alphanumeric symbols instead of 0’s and l’s.
 These alphanumeric symbols will be known as mnemonic
codes and can have maximum up to 5 letter combination
e.g. ADD for addition, SUB for subtraction, START,LABEL
etc. Because of this feature it is also known as ‘Symbolic
Programming Language’.
Low Level Languages
 Assembly Language (Cont..)
 This language is also very difficult and needs a lot of
practice to master it because very small English
support is given to this language.
 The language mainly helps in compiler orientations.
The instructions of the Assembly language will also
be converted to machine codes by language
translator to be executed by the computer.
High Level Language
High Level Language
 User Friendly
 High level computer languages give formats close to
English language
 Purpose of developing high level languages is to enable
people to write programs easily and in their own native
language environment (English).
 High-level languages are basically symbolic languages
that use English words and/or mathematical symbols
rather than mnemonic codes.
 Each instruction in the high level language is translated
into many machine language instructions thus showing
one-to-many translation
Types of High Level Languages
Algebraic Formula-Type Processing: computational
1.
procedures for solving mathematical and statistical problem
i.
ii.
iii.
iv.
v.
BASIC (Beginners All Purpose Symbolic Instruction Code).
FORTRAN (Formula Translation).
PL/I (Programming Language, Version 1).
ALGOL (Algorithmic Language).
APL (A Programming Language).
Business Data Processing: maintaining data processing
2.
procedures and files handling problems.
i.
ii.
COBOL (Common Business Oriented Language).
RPG (Report Program Generator
Types of High Level Languages (Cont…)
3. String and List Processing: These are used for string
manipulation including search for patterns, inserting and deleting
characters. Examples are:
i.
ii.
LISP (List Processing).
Prolog (Program in Logic).
4. Object Oriented Programming Language: In OOP, the
computer program is divided into objects. Examples are:
i.
ii.
C++
Java
5. Visual programming language: these are designed
for building Windows-based applications Examples are:
i.
ii.
iii.
Visual Basic
Visual Java
Visual C
Algorithms
 "a set of rules that precisely defines a sequence of
operations”
 effective method expressed as a finite list of well-defined
instructions for calculating a function.
 Starting from an initial state and initial input (perhaps
empty), the instructions describe a computation that, when
executed, proceeds through a finite number of well-defined
successive states, eventually producing "output“ and
terminating at a final ending state.
Algorithms (Cont…)
Algorithms (Cont…)
Expressing Algorithms
 Natural language expressions of algorithms tend to be
verbose and ambiguous, and are rarely used for complex or
technical algorithms.
 Pseudocode, flowcharts and control tables are
structured ways to express algorithms that avoid many of
the ambiguities common in natural language statements.
 Programming languages are primarily intended for
expressing algorithms in a form that can be executed by a
computer, but are often used as a way to define or
document algorithms.
Algorithms (Cont…)
Algorithms (Cont…)
 In computer systems, an algorithm is basically an
instance of logic written in software by software
developers to be effective for the intended "target"
computer(s) for the target machines to produce
output from given input.
Compiler
 A compiler is a computer program (or set of
programs) that transforms source code written in a
programming language (the source language) into
another computer language (the target language,
often having a binary form known as object code).
 The most common reason for wanting to transform
source code is to create an executable program.
Compiler (Cont…)
 Compilers bridge source programs in high-level
languages with the underlying hardware.
 A compiler requires ;
i.
ii.
iii.
iv.
determining the correctness of the syntax of programs,
generating correct and efficient object code,
run-time organization,
formatting output according to assembler and/or linker
conventions.
Compiler (Cont…)
Compiler (Cont…)
Structure of Compiler
 The front end checks whether the program is correctly written in
terms of the programming language syntax and semantics. Errors are
reported if any, in a useful way. The frontend then generates an
intermediate representation or IR of the source code for processing by
the middle-end.
 The middle end is where optimization takes place. Typical
transformations for optimization are removal of useless or unreachable
code, discovery and propagation of constant values, relocation of
computation to a less frequently executed place (e.g., out of a loop), or
specialization of computation based on the context.
 The back end is responsible for translating the IR from the middleend into assembly code. The target instruction(s) are chosen for each
IR instruction. Register allocation assigns processor registers for the
program variables where possible
Compiler (Cont…)
Interpreter
 Computer program that executes, i.e. performs,
instructions written in a programming language.
 An interpreter generally uses one of the following
strategies for program execution:



execute the source code directly
translate source code into some efficient intermediate representation
and immediately execute this
explicitly execute stored precompiled code made by a compiler which
is part of the interpreter system
Interpreter VS Compiler
 Programs are usually written in high level code,
which has to be converted into machine code for the
CPU to execute it.
 This conversion is done by either a compiler or an
interpreter.
 A compiler makes the conversion just once, while an
interpreter typically converts it every time a program
is executed (or in some languages like early versions
of BASIC, every time a single instruction is
executed).
Assembler
 A computer program which translates from assembly
language to an object file or machine language
format.
 An assembler creates object code by translating
assembly instruction mnemonics into opcodes, and
by resolving symbolic names for memory locations
and other entities.
 The use of symbolic references is a key feature of
assemblers, saving tedious calculations and manual
address updates after program modifications
Data & Information
 Facts, figures, values, pictures in raw form
 Information: Facts, figures, values, pictures in well
organized form
Type
char
Explanation
Type
smallest addressable unit of
signed char
the machine that can
contain basic character set.
It is an integer type. Actual
type can be either signed or
unsigned char
unsigned depending on
implementation
Explanation
same as char, but
guaranteed to be signed.
same as char, but
guaranteed to be unsigned.
short
short int
signed short
signed short int
short signed integer type. At unsigned short
unsigned short int
least 16 bits in size.
same as short, but
unsigned.
int
signed int
basic signed integer type. At unsigned
unsigned int
least 16 bits in size.
same as int, but unsigned.
long
long int
signed long
signed long int
long signed integer type. At unsigned long
unsigned long int
least 32 bits in size.
same as long, but unsigned.
long long
long long int
long long signed integer
signed long long
type. At least 64 bits in
signed long long in size.
t
float
(single precision) floatingpoint type.
unsigned long long
same as long long, but
unsigned long long i
unsigned.
nt
double
double precision floating-point type.
long double
extended precision floating-point type.
Download