+ All Categories
Home > Documents > ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Date post: 25-Dec-2015
Category:
Upload: myron-hensley
View: 223 times
Download: 0 times
Share this document with a friend
Popular Tags:
43
ENGR. SHOAIB ASLAM Computer Programming I Lecture 02
Transcript
Page 1: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

ENGR. SHOAIB ASLAM

Computer Programming ILecture 02

Page 2: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Contents

Computer LanguagesMachine LanguagesAlgorithmsCompilerInterpreterAssembler

Page 3: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

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

Page 4: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

TYPES Basically, languages are divided into two categories according to

their interpretation.Low Level LanguagesHigh Level Languages

Computer Languages

Page 5: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

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

Page 6: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Machine LanguageLowest and most elementary level of Programming

languageFirst 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

Page 7: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 8: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 9: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

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

Page 10: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 11: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

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.

Low Level Languages

Page 12: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 13: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

High Level Language

Page 14: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

High Level Language

User FriendlyHigh level computer languages give formats close

to English languagePurpose 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

Page 15: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 16: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 17: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 18: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Types of High Level Languages

1. Algebraic Formula-Type Processing: computational procedures for solving mathematical and statistical problem

i. BASIC (Beginners All Purpose Symbolic Instruction Code).ii.  FORTRAN (Formula Translation).iii.  PL/I (Programming Language, Version 1).iv.  ALGOL (Algorithmic Language).v.  APL (A Programming Language).

2. Business Data Processing: maintaining data processing procedures and files handling problems.

i. COBOL (Common Business Oriented Language).ii.   RPG (Report Program Generator

Page 19: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

3. String and List Processing: These are used for string manipulation including search for patterns, inserting and deleting characters. Examples are:

i. LISP (List Processing).ii. Prolog (Program in Logic).

4. Object Oriented Programming Language: In OOP, the computer program is divided into objects. Examples are:

i. C++ii.  Java

5. Visual programming language: these are designed for building Windows-based applications Examples are:

i. Visual Basicii. Visual Javaiii. Visual C

Types of High Level Languages (Cont…)

Page 20: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 21: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 22: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

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.

Page 23: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Algorithms (Cont…)

Page 24: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 25: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Expressing AlgorithmsNatural 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…)

Page 26: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Algorithms (Cont…)

Page 27: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

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.

Algorithms (Cont…)

Page 28: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 29: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

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.

Page 30: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Compilers bridge source programs in high-level languages with the underlying hardware.

A compiler requires ;i. determining the correctness of the syntax of

programs,ii. generating correct and efficient object code, iii. run-time organization, iv. formatting output according to assembler

and/or linker conventions.

Compiler (Cont…)

Page 31: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Compiler (Cont…)

Page 32: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

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 middle-end 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…)

Page 33: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Compiler (Cont…)

Page 34: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

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

Page 35: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 36: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

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).

Page 37: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 38: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

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

Page 39: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 40: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.
Page 41: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Data & Information

Facts, figures, values, pictures in raw form

Information: Facts, figures, values, pictures in well organized form

Page 42: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

Type Explanation Type Explanation

char

smallest addressable unit of the machine that can contain basic character set. It is an integer type. Actual type can be either signed or unsigned depending on implementation

signed charsame as char, but guaranteed to be signed.

unsigned charsame as char, but guaranteed to be unsigned.

shortshort intsigned shortsigned short int

short signed integer type. At least 16 bits in size.

unsigned shortunsigned short int

same as short, but unsigned.

intsigned int

basic signed integer type. At least 16 bits in size.

unsignedunsigned int

same as int, but unsigned.

longlong intsigned longsigned long int

long signed integer type. At least 32 bits in size.

unsigned longunsigned long int

same as long, but unsigned.

long longlong long intsigned long longsigned long long int

long long signed integer type. At least 64 bits in size.

unsigned long longunsigned long long int

same as long long, but unsigned.

float(single precision) floating-point type.

Page 43: ENGR. SHOAIB ASLAM Computer Programming I Lecture 02.

doubledouble precision floating-point type.

long doubleextended precision floating-point type.


Recommended