Sie sind auf Seite 1von 49

BRIDGE COURSE PROBLEM SOLVING AND PROGRAMMING

PSP - Bridge Course 2010-2013 Batch- AS

Introduction
Why computers? What is a computer? How are computers built? How are computers programmed?

PSP - Bridge Course 2010-2013 Batch- AS

Why Computers?

PSP - Bridge Course 2010-2013 Batch- AS

What is a computer?
Is it a calculating device Is it a data processor
Performing arithmetic operations at enormous speed

Device which operates upon data Capturing the data, manipulating the data, & managing the output

Is it a communication device

men will be able to communicate more effectively through a machine than face to face. Send / receive through channel

Is it a programming device Is it gaming device

lot of application softwares are built

Of course, computer games, virtual reality games, second life, avatar etc

and much more..

PSP - Bridge Course 2010-2013 Batch- AS

Characteristics of Computer
Automatic Speed Accuracy Versatility Power of remembering Diligence

PSP - Bridge Course 2010-2013 Batch- AS

How it is Built ?
In the Beginning

PSP - Bridge Course 2010-2013 Batch- AS

How it is Built ? (contd..)

PSP - Bridge Course 2010-2013 Batch- AS

How it is Built ? (contd..)

PSP - Bridge Course 2010-2013 Batch- AS

How it is Built ? (contd..)

Now most peoples computer ..

PSP - Bridge Course 2010-2013 Batch- AS

CRT Display

The Box

CD-ROM Drive

Floppy Disk Drive Keyboard

Mouse
PSP - Bridge Course 2010-2013 Batch- AS

PSP - Bridge Course 2010-2013 Batch- AS

Evolution Of Computers
First Generation (1942 1955)
Vacuum tubes, electro magnetic relay memory, punched cards Machine & Assembly languages

Second Generation (1955 1964)

Transistors, magnetic core memory, tapes & disks Batch OS, High level Programming languages

Third Generation (1964 1975)

ICs, larger capacity disks, mini computers Time sharing OS, unbundling s/w from h/w

Fourth Generation (1975 -1989)

ICs, VLSI, micro processors, PCs, Computer networks OS for PCs, GUI, Windows, UNIX

Fifth Generation (1989 present)

ICs, ULSI, Optical disks, Dual core, laptops, notebooks WWW, Internet, multimedia applications

PSP - Bridge Course 2010-2013 Batch- AS

Typical Computer System - Inside the Box

Processor: Brains Memory: Scratch paper Disk : Long term memory I/O: Communication

PSP - Bridge Course 2010-2013 Batch- AS

Typical Computer System - Inside the Box (contd..)


Motherboard

PSP - Bridge Course 2010-2013 Batch- AS

Schematic Diagram of a Personal Computer... bus


Printer
Mouse Keyboard Modem

Ports

Disk controller Graphics card Monitor

CPU RAM

Sound card
Network card

Speakers

Computer
PSP - Bridge Course 2010-2013 Batch- AS

Von Neumann Model


Memory Unit

Input Unit

Arithmetic and Logical Unit (ALU)

Output Unit

Control Unit
PSP - Bridge Course 2010-2013 Batch- AS

Von Neumann Model (contd..)

Memory Unit

CPU
Arithmetic and Logical Unit (ALU)

Input Unit

Output Unit

Control Unit
PSP - Bridge Course 2010-2013 Batch- AS

Computers Summary (contd..)

PSP - Bridge Course 2010-2013 Batch- AS

Hardware Vs Software
Hardware is best described as a device that is physically connected to the computer or something that can be physically touched. Hardware serve as the delivery system for software solutions. Software is a general term used to describe a collection of computer programs, procedures, and documentation that perform some task on a computer system. Software is an ordered sequence of instructions for changing the state of the computer hardware in a particular sequence.

PSP - Bridge Course 2010-2013 Batch- AS

Hardware Vs Software

PSP - Bridge Course 2010-2013 Batch- AS

Language of Computers
Computers speak binary. Binary language consists of combinations of 1's and 0's that represent characters of other languages Dont make the mistake of thinking that little 1's and 0's are running around inside of the computer. We humans prefer to think of 1's and 0's because its easier than visualizing positive and negative current flows or open and closed circuits which is what actually happens inside computers.

You know about ..


Bit and Bytes

PSP - Bridge Course 2010-2013 Batch- AS

How will you Program Computers Machine Language


Computers know only binary

0001 1101 1111 0000 0001

0011 0111 0001 1100 0011

0011 0001 1101 0101 0011

1011 1001 1111 1101 1011

Do you think that the above instructions make any sense ? Of course, these instructions have no real meaning to you, but they are exactly the kind of instructions that a computer expects. Instructions like these are called "machine code" and each one represents a typical operation that a computer might perform.

PSP - Bridge Course 2010-2013 Batch- AS

MACHINE LANGUAGE (contd..)

Conclusion about machine language ( first generation language) Even though writing code in machine language is very appropriate for a computer, but it is extremely confusing for a programmer.

So we need some new generation of languages for writing programs.

PSP - Bridge Course 2010-2013 Batch- AS

ASSEMBLY LANGUAGE
Machine Code Assembly Code

0001 1101 1111 0000 0001

0011 0111 0001 1100 0011

0011 0001 1101 0101 0011

1011 1001 1111 1101 1011

LOAD A MULT B STORE C LOAD D ADD C STORE RES

In assembly languages, set of symbolic names are used to represent the operations. So writing assembly code is simpler than writing machine code.

PSP - Bridge Course 2010-2013 Batch- AS

ASSEMBLY LANGUAGE (contd..)


Some examples of Assembly language
1. x86 assembly language Is the assembly language for the x86 class of processors, which includes Intel's Pentium series and AMD's Atholn series 2. 80x86 assembly language

PSP - Bridge Course 2010-2013 Batch- AS

ASSEMBLY LANGUAGE (contd..)


Advantages The symbolic keywords are easier to code and saves time and effort It is easier to correct errors and modify programming instructions Assembly codes has got almost the same efficiency of execution as the machine level language, because there is one-to-one translation between assembly language program and its corresponding machine language program.

Limitations Code written in assembly language is machine dependent. (code written for one machine will not run on another machine.)

PSP - Bridge Course 2010-2013 Batch- AS

HIGH LEVEL LANGUAGES


In Assembly language, as per the previous example

RES = (A*B) + D is represented with 6 lines of code.


It will be even more simpler if any language could represent the above calculation in single line of code. So, the third generation languages evolved as general purpose languages. They further increased the ease of programming by grouping sets of machine instructions together to form common programming constructs These languages are also known as high-level languages since they abstract away the details of machine code and help programmers to concentrate on problem solving.

PSP - Bridge Course 2010-2013 Batch- AS

HIGH LEVEL LANGUAGE (contd..)

Advantages of high level languages 1. It is easier to write programs in high level language than other low level and assembly languages 2. Code written in high level languages are portable 3. It also offers maintainability

PSP - Bridge Course 2010-2013 Batch- AS

PROGRAMMING ENVIRONMENT

Programming Environment is the environment in which programs are created, tested and executed.

PSP - Bridge Course 2010-2013 Batch- AS

Writing Programs Use some text editors for typing programs Save the programs with proper extensions in the desired directory

PSP - Bridge Course 2010-2013 Batch- AS

Execution of a program involves the following steps: Translation of the program (Why?)

Linking of the program with other programs needed for its execution Relocation of the program to execute from the specific memory area allocated to it Loading of the program in the main memory for the purpose of execution

PSP - Bridge Course 2010-2013 Batch- AS

ROLE OF TRANSALTAORS

If we write programs in machine language, it will be understandable by the computer and can be executed directly. But if we write code in either assembly language or high level language, is it possible to execute them directly? Here comes the role of Translators which translates the code written in assembly language or high level language to machine code. The following are the categories of translators Assemblers Compilers Interpreters

PSP - Bridge Course 2010-2013 Batch- AS

Stages of a Program

High Level Language Level (translation)

(Basic, Pascal, C)

Assembly Language Level


(translation) Operating System Level (partial interpretation) Conventional Machine Level

(sometimes bypassed)

(100110101)

(interpretation)
Microprocessor Level (optional)

PSP - Bridge Course 2010-2013 Batch- AS

Translators
Assembler: Is a translator program which translates the code written in assembly language to corresponding machine language. Compiler: Is a translator program which translates the code written in high level language to corresponding machine language. Interpreters: Is a translator program which translates the code written in high level language to corresponding machine language.

Then what is the difference between complier and interpreters ?

PSP - Bridge Course 2010-2013 Batch- AS

Compiler
A compiler translates a complete source program written in high level languages into machine code. The whole source code file is compiled in one go, and a complete, compiled version of the code (object code) is produced. This can be saved on some secondary storage medium (e.g. floppy disk, hard disk...) and can be used later. In compilation, The program can only be executed once translation is complete Any changes to the source code require a complete recompilation. Once compiled, it can be re-run any number of times.

PSP - Bridge Course 2010-2013 Batch- AS

Interpreter
An interpreter performs on-the-fly translation It provides a means by which a program written in source language can be understood and executed by the CPU line by line. As the first line is encountered by the interpreter, it is translated and executed. Then it moves to the next line of source code and repeats the process.

In interpretation, Statements from the source program are fetched and executed one by one. No copy of the translation exists, and if the program is to be re-run, it has to be interpreted all over again.

PSP - Bridge Course 2010-2013 Batch- AS

PHASES OF COMPLIERS
A typical compiler consists of two phases of compilation. Analysis phase Synthesis phase. In analysis phase, the source program is divided in to constituent pieces and creates intermediate representation. There will be lexical, syntactic and semantic analysis. In synthesis phase, the target program is generated from the intermediate representation. Code optimization will also be handled at this phase.

PSP - Bridge Course 2010-2013 Batch- AS

PHASES OF COMPLIERS (contd..)

PSP - Bridge Course 2010-2013 Batch- AS

PHASES OF COMPLIERS (contd..)


Lexical Analyzer ( Scanner)

Scan the source program and separate the lexical units in it.
Example : c = a + b;

At the end of lexical analysis, the following lexical units are identified. cab=+ ( here c a b are the identifiers and = + are the operators)

PSP - Bridge Course 2010-2013 Batch- AS

PHASES OF COMPLIERS (contd..)


Syntax analysis will construct the parse tree and check the grammar of the instruction. Semantic analysis will check the meaning and produce intermediate code. Synthesis phase will create the target code from the intermediate code.

PSP - Bridge Course 2010-2013 Batch- AS

PROGRAM LINKING

Linking is the process of putting together other program files and functions (external references) that are required by the program.

PSP - Bridge Course 2010-2013 Batch- AS

PROCESS OF PRODUCING AN EXECUTABLE FILE

PSP - Bridge Course 2010-2013 Batch- AS

PROGRAM LOADING
During execution, the executable object code is loaded into the main memory by the loader program and the program instructions are executed.

The tasks are,


1. Read executable files header to determine the size of text and data segments 2. Create a new address space for the program

3. Copies instructions and data into address space


4. Copies arguments passed to the program on the stack 5. Initializes the machine registers including the stack pointer

6. Jumps to a startup routine that copies the programs arguments from the stack to registers and calls the programs main routine

PSP - Bridge Course 2010-2013 Batch- AS

PROGRAM LOADING (contd..)

PSP - Bridge Course 2010-2013 Batch- AS

Example Execution of C Program

PSP - Bridge Course 2010-2013 Batch- AS

CATEGORIES OF PROGRAMMING LANGUAGES

4GL

High Level Language

Assembly Language

Machine Level Language

PSP - Bridge Course 2010-2013 Batch- AS

FOURTH GENERATION LANGUAGES


4GL or fourth-generation language is designed to be closer to natural language than a 3GL language Even closer to how people think about their problems Special purpose Scripting languages Querying languages Languages for AI

PSP - Bridge Course 2010-2013 Batch- AS

IDEs
An integrated development environment (IDE) is a programming environment that has been packaged as an application program, typically consisting of a code editor, a compiler, a debugger, and a graphical user interface (GUI) builder. The IDE may be a standalone application or may be included as part of one or more existing and compatible applications. Most IDEs have tools that allow you to: Write and edit source code See errors as you type See highlighted code syntax Automate repetitive tasks Compile code Browse class structures Use drag-and-drop utilities for easy building of features, such as graphic objects or creating database connections

Example : For Java NetBeans , Eclipse

PSP - Bridge Course 2010-2013 Batch- AS

CHOICE OF PROGRAMMING LANGUAGE

The choice depends on the requirements to be implemented and on external factors such as availability, support and training.

PSP - Bridge Course 2010-2013 Batch- AS

Das könnte Ihnen auch gefallen