Top Banner
Department of Computer Science & Engg. SGI,SAMALKHA MANOJ SHARMA, Lecturer Computer Science,SGI E-mail: [email protected] Introduction to Computers - Languages
16
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: PL1-PPT

Department of Computer Science & Engg.SGI,SAMALKHA

MANOJ SHARMA, LecturerComputer Science,SGIE-mail: [email protected]

Introduction to Computers - Languages

Page 2: PL1-PPT

Computer OrganizationComputer Organization

A Typical Von-Neumann ArchitectureA Typical Von-Neumann Architecture

Example:Example:

1.1. InputInput unit unit2.2. OutputOutput unit unit 3.3. MemoryMemory unit unit 4.4. Arithmetic and logicArithmetic and logic unit (ALU) unit (ALU) 5.5. Central processingCentral processing unit (CPU) unit (CPU) 6.6. Secondary storageSecondary storage unit unit

Control Circuit(ex: PC: Program Counter)

ALUMemory I/O

CPU

Page 3: PL1-PPT

Programming LanguagesProgramming Languages1.1. Machine languages (machine dependent)Machine languages (machine dependent)

Native tongue of a particular kind of computer. Each Native tongue of a particular kind of computer. Each instruction is a binary string. The code is used to indicate instruction is a binary string. The code is used to indicate the operations to be performed and the memory cells to be the operations to be performed and the memory cells to be addressed. This form is easiest form of computers to addressed. This form is easiest form of computers to understand, but is most difficult for a person to understand.understand, but is most difficult for a person to understand.Strings of numbers giving machine specific instructionsStrings of numbers giving machine specific instructions

Example:Example: +1300042774+1300042774+1400593419+1400593419+1200274027+1200274027

Page 4: PL1-PPT

Programming Languages Programming Languages (cont.)(cont.)

2.2. Assembly languages (machine dependent)Assembly languages (machine dependent)English-like abbreviations representing elementary computer English-like abbreviations representing elementary computer operations (translated via assemblers)operations (translated via assemblers)Again specific to only one type of computer. Uses descriptive Again specific to only one type of computer. Uses descriptive names for operations and data, names for operations and data, e.ge.g. , “LOAD value”, “ADD . , “LOAD value”, “ADD delta”, “STORE value”. Assemblers will translate these to delta”, “STORE value”. Assemblers will translate these to machine languages. Intermediate level. Somewhat machine languages. Intermediate level. Somewhat descriptive, but basically following the machine instructions.descriptive, but basically following the machine instructions.

Example:Example: LOAD BASEPAYLOAD BASEPAYADD OVERPAYADD OVERPAYSTORE GROSSPAYSTORE GROSSPAY

Page 5: PL1-PPT

Programming Languages Programming Languages (cont.)(cont.)

3.3. High-level languages High-level languages (machine independent)(machine independent)Codes similar to everyday EnglishCodes similar to everyday English

High-level languages: Write program instructions called High-level languages: Write program instructions called statementstatement that resemble a limited version of English. that resemble a limited version of English. e.ge.g., the statement ., the statement “value = value + delta”. “value = value + delta”. PortablePortable, meaning it can be used on , meaning it can be used on different types of computers without modifications. Compilers different types of computers without modifications. Compilers translate them to machine languages. Examples are FORTRAN, translate them to machine languages. Examples are FORTRAN, PASCAL, COBOL, C, C++, BASIC etc. PASCAL, COBOL, C, C++, BASIC etc.

Use mathematical notations (translated via compilers)Use mathematical notations (translated via compilers)Example:Example:

grossPay = basePay + overTimePaygrossPay = basePay + overTimePay

Example:Example:

Statement: a= a + ba= a + b

10

7

17

7

a

b

a

b

Before

After

Page 6: PL1-PPT

Programming Languages Programming Languages (cont.)(cont.)

Structured programming Structured programming Disciplined approach to writing programsDisciplined approach to writing programs

Clear, easy to test and debug and easy to modifyClear, easy to test and debug and easy to modify

MultitaskingMultitaskingSpecifying that manySpecifying that many

activities run in parallel (still timesliced)activities run in parallel (still timesliced)Language Application Area

FORTRAN Scientific programming Formula TranslationCOBOL Business data Processing Common Business-Oriented LanguageLisp Artificial Intelligence (AI) List ProcessingC System Programming Predecessor BProlog AI Logic ProgrammingAda Real-time distributed systems Ada Augusta Byron & Charles BabbageSmalltalk GUI, OOP Objects “talk” via messageC++ Supports object & OOP C (++ is the increment operator)JAVA SupportsWeb programming Originally named “Oak”

Origin of Name

Page 7: PL1-PPT

Semantic GapSemantic Gap

A “semantic gap” exists between the amount of A “semantic gap” exists between the amount of information conveyed in assembly language v high level information conveyed in assembly language v high level languages. Consider the following C single statement:languages. Consider the following C single statement: x = x + 3; x = x + 3;

This single statement may require many assembly This single statement may require many assembly language statements (operations):language statements (operations): Load memory location 24 into accumulator Load memory location 24 into accumulator Add a constant 3 to the accumulator Add a constant 3 to the accumulator Store accumulator in memory location 24 Store accumulator in memory location 24

The number of executable statement expands greatly The number of executable statement expands greatly during the translation process from a high level during the translation process from a high level language into assembly language.language into assembly language.

Page 8: PL1-PPT

C Programming LanguageC Programming LanguageC

High-level general-purpose language developed in 1972 at AT&T Bell High-level general-purpose language developed in 1972 at AT&T Bell Lab. By Dennis Ritchie Lab. By Dennis Ritchie from two previous programming BCPL and Bfrom two previous programming BCPL and B

Originally developed to write the UNIX operating systemOriginally developed to write the UNIX operating systemHardware independent (portable)Hardware independent (portable)

By late 1970's C had evolved to "Traditional C"By late 1970's C had evolved to "Traditional C"

Today, virtually all new operating systems are written in C or C++.Today, virtually all new operating systems are written in C or C++.

The current standard in C is ANSI C. The current standard in C is ANSI C.

C++ is a more advanced version of C, incorporating among other C++ is a more advanced version of C, incorporating among other things, the object-oriented constructsthings, the object-oriented constructs

StandardizationStandardizationMany slight variations of C existed, and were incompatibleMany slight variations of C existed, and were incompatible

Committee formed to create a "unambiguous, machine-independent" definitionCommittee formed to create a "unambiguous, machine-independent" definition

Standard created in 1989, updated in 1999Standard created in 1989, updated in 1999

C has become a popular language industry due its power and C has become a popular language industry due its power and flexibilityflexibility

Page 9: PL1-PPT

The C Standard LibraryThe C Standard LibraryC programs consist of pieces/modules called C programs consist of pieces/modules called functionsfunctions

A programmer can create his own functionsA programmer can create his own functionsAdvantage: the programmer knows exactly how it worksAdvantage: the programmer knows exactly how it worksDisadvantage: time consumingDisadvantage: time consuming

Programmers will often use the C library Programmers will often use the C library functionsfunctions

Use these as building blocksUse these as building blocks

Avoid re-inventing the wheelAvoid re-inventing the wheelIf a pre-made function exists, generally best to use it If a pre-made function exists, generally best to use it rather than write your ownrather than write your ownLibrary functions carefully written, efficient, and portableLibrary functions carefully written, efficient, and portable

Page 10: PL1-PPT

The C Standard Library The C Standard Library (cont.)(cont.)

The Key Software Trend: Objects in C++ and The Key Software Trend: Objects in C++ and JAVAJAVA

Reusable software components that model items in the Reusable software components that model items in the real worldreal world

Meaningful software units: ex: Meaningful software units: ex: Date objects, time objects, audio Date objects, time objects, audio

objects, video objects, file objects, record objects…aobjects, video objects, file objects, record objects…any noun can ny noun can be represented as an objectbe represented as an object

More understandable, better organized, and easier to More understandable, better organized, and easier to maintain than procedural programmingmaintain than procedural programming

Favor modularityFavor modularity

Page 11: PL1-PPT

The C Standard LibraryThe C Standard Library

#include <stdio.h>#include <stdio.h>

main()main()

{{

int i;int i;

for (i = 0; i ++; i < 10)for (i = 0; i ++; i < 10)

{ {

printf ("Hello World!\n");printf ("Hello World!\n");

}}

}}

Page 12: PL1-PPT

A Typical C Program Development EnvironmentA Typical C Program Development Environment

1.1. EditEdit

2.2. PreprocessPreprocess

3.3. CompileCompile

4.4. LinkLink

5.5. LoadLoad

6.6. ExecuteExecute Disk

Disk

Loader

Linker

Compiler

Preprocessor

Editor

Disk

Disk

Disk

Primary Memory

CPU

Primary Memory

1. Program is created in the editor and stored on disk

2. Preprocessor program processes the code

3. Compiler creates object code and stores it on disk.

5. Loader puts program in memory.

4. Linker links the object code with the libraries

6. CPU takes each instruction and executes it, possibly storing new data values as the program executes

•Phases of C Programs:

Page 13: PL1-PPT

A Typical C Program Development Environment A Typical C Program Development Environment (cont.)(cont.)

• Procedure to Prepare a C Program for ExecutionProcedure to Prepare a C Program for ExecutionEnter the program code and save as a source (*.c) file using Word Processor (editor)

The linker links the new object file with other object files

The loader places the executable file into memory

Executable program in memory

Failure

Success

Source (.c)file on disk

(Format: text)

Revisedsource file

New object(*.obj) files

(Format: binary)

Executable(*.exe, *.out) file(Format: binary) Welcome to

CSCI230

Other object(*.obj) files

Correct syntax errors

List of errors

Compiler attempts to translate the programinto machine code

Input data

Results

Page 14: PL1-PPT

Constructs in C LanguageConstructs in C LanguageType Declarations: Type Declarations: ex: ex: int, float,…

I/O: I/O: ex: ex: printf(), scanf()

Arithmetic and LogicalArithmetic and Logical Operations: Operations: ex: ex: +,-,*,/,%,>,<,==,…

Arrays, Pointers, Structures, Unions, …Arrays, Pointers, Structures, Unions, …

FunctionsFunctionsArguments & return valuesArguments & return values

RecursionRecursion

Control Mechanisms: Control Mechanisms: ex: ex: if, else, while, for,…

Characters & Strings: Characters & Strings: ex: ex: strcat(), strcpy(), …

File Processing: File Processing: ex:ex: fopen(), fclose(), …

Pre-processor: Pre-processor: ex: ex: #define …

Misc.Misc.bit operations, ...

Page 15: PL1-PPT

Operation System (OS)Operation System (OS)

Responsibilities:Responsibilities:Communicating with the computer userCommunicating with the computer userManaging allocation of memory, of processorManaging allocation of memory, of processortime, and of other resources for various taskstime, and of other resources for various tasksI/O handling: BIOS vs DOS services (Interrupts)I/O handling: BIOS vs DOS services (Interrupts)Read/Write data from secondary storageRead/Write data from secondary storage

Evolution of Operating SystemsEvolution of Operating SystemsBatch processing:Batch processing: do only one job or task at a time do only one job or task at a timeOperating systems:Operating systems: manage transitions between jobs and manage transitions between jobs and Increase throughput (amount of work computers process)Increase throughput (amount of work computers process)Multiprogramming:Multiprogramming: Computer resources are shared by many Computer resources are shared by many jobs or tasksjobs or tasksTimesharing:Timesharing: Technique used to implement multiprogramming Technique used to implement multiprogramming where the computer runs a small portion of one user’s job where the computer runs a small portion of one user’s job then moves on to service the next userthen moves on to service the next user

Command-lineInterface

Graphical UserInterface (GUI)

UNIX MacOSMS_DOS WindowsVMS X Windows (linux and solaris)

Page 16: PL1-PPT

Application SoftwareApplication Software

Developed to assist a computer user in Developed to assist a computer user in accomplishing special tasksaccomplishing special tasks

ex: word processing applications: MS-word or ex: word processing applications: MS-word or Word-perfectWord-perfectex: Spreadsheet applications: Lotus1-2-3, Excelex: Spreadsheet applications: Lotus1-2-3, Excelex: Database: Oracle, MS-Accessex: Database: Oracle, MS-Access

Software Development Life Cycle (SDLC)Software Development Life Cycle (SDLC)ProblemProblem: specify the problem requirements: specify the problem requirementsAnalysisAnalysis: analyze the problem: analyze the problemDesignDesign: design the algorithm to solve the problem: design the algorithm to solve the problemImplementationImplementation: Implement the algorithm: Implement the algorithmTestingTesting: test and verify the completed program: test and verify the completed programMaintenanceMaintenance: maintain and update the program: maintain and update the program