t 01 b computer intro languages

Upload: pankaj-mohindra

Post on 06-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 t 01 b Computer Intro Languages

    1/16

    NANKANA SAHIB COLLEGE OF

    EDUCATION

    Submitted to :

    Gaganpreet Kaur

    Introduction to Computers- Languages

    Submitted By :

    Paramjeet KaurRoll No. 97

  • 8/3/2019 t 01 b Computer Intro Languages

    2/16

    Computer OrganizationComputer Organization

    A Typical VonA Typical Von--Neumann ArchitectureNeumann Architecture

    Example:Example:

    1.1. InputInputunitunit2.2. OutputOutputunitunit

    3.3. MemoryMemoryunitunit

    4.4. Arithmetic and logicArithmetic and logicunit (ALU)unit (ALU)

    5.5. Central processingCentral processingunit (CPU)unit (CPU)

    6.6. Secondary storageSecondary storage unitunit

    Control Circuit

    (ex: PC: Program Counter)

    ALU

    Memor

    y

    I/O

    CPU

  • 8/3/2019 t 01 b Computer Intro Languages

    3/16

    Programming LanguagesProgramming Languages

    1.1. Machine languages (machine

    Machine languages (machinedependent)dependent)NativeNative tonguetongue of of aa particularparticular kindkind of ofcomputercomputer.. EachEach instructioninstruction isis aa binarybinarystringstring.. TheThe codecode isis usedused toto indicateindicate thetheoperationsoperations toto bebe performedperformed andand thethe

    memorymemory cellscells toto bebe addressedaddressed.. ThisThis formform isiseasiesteasiest formform ofof computerscomputers toto understand,understand,butbut isis mostmost difficultdifficult forfor aa personperson totounderstandunderstand..

    Strings of numbers giving machine specificStrings of numbers giving machine specificinstructionsinstructions

    Example:Example: +1300042774+1300042774

    +1400593419+1400593419

    +1200274027+1200274027

  • 8/3/2019 t 01 b Computer Intro Languages

    4/16

    Programming LanguagesProgramming Languages (cont.)(cont.)

    2.2. Assembly languages (machineAssembly languages (machinedependent)dependent)EnglishEnglish--likelike abbreviationsabbreviations representingrepresentingelementaryelementary computercomputer operationsoperations (translated(translatedviavia assemblers)assemblers)

    AgainAgain specificspecific toto onlyonly oneone typetype ofof computercomputer..UsesUses descriptivedescriptive namesnames forfor operationsoperations andanddata,data, ee..gg.. ,, LOADLOAD value,value, ADDADD delta,delta,STORESTORE valuevalue.. AssemblersAssemblers willwill translatetranslatethesethese toto machinemachine languageslanguages.. IntermediateIntermediatelevellevel.. SomewhatSomewhat descriptive,descriptive, butbut basicallybasicallyfollowingfollowing thethe machinemachine instructionsinstructions..

    Example:Example: LOAD BASEPAYLOAD BASEPAY

    ADD OVERPAY ADD OVERPAY

    STORE GROSSPAYSTORE GROSSPAY

  • 8/3/2019 t 01 b Computer Intro Languages

    5/16

    Programming LanguagesProgramming Languages(cont.)(cont.)

    3.3. HighHigh--level languageslevel languages (machine(machineindependent)independent)

    Codes similar to everyday EnglishCodes similar to everyday English

    HighHigh--levellevel languageslanguages:: WriteWrite programprogram instructionsinstructions

    calledcalled statementstatement thatthat resembleresemble aa limitedlimited versionversion

    ofof EnglishEnglish.. ee..gg..,, thethe statementstatement

    valuevalue == valuevalue ++ deltadelta.. PortablePortable,, meaningmeaning itit cancan

    bebe usedused onon differentdifferent typestypes ofof computerscomputers withoutwithout

    modificationsmodifications.. CompilersCompilers translatetranslate themthem toto

    machinemachine languageslanguages.. ExamplesExamples areare FORTRAN,FORTRAN,

    PASCAL,PASCAL, COBOL,COBOL, C,C, C++,C++, BASICBASIC etcetc..Use mathematical notations (translated viaUse mathematical notations (translated via

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

  • 8/3/2019 t 01 b Computer Intro Languages

    6/16

    Programming LanguagesProgramming Languages(cont.)(cont.)

    Structured programmingStructured programmingDisciplined 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

    MultitaskingMultitasking

    Specifying that manySpecifying that many

    activities run in parallel (still timesliced)activities run in parallel (still timesliced)

    Language Application Area

    FORTRAN Scientific programming Formula Translation

    COBOL Business data Processing Common Business-Oriented Language

    Lisp Artificial Intelligence (AI) List Processing

    C System Programming Predecessor B

    Prolog AI Logic Programming

    Ada Real-time distributed systems Ada Augusta

    Byron & Charles Babbage

    Smalltalk GUI, OOP Objects talk via messageC++ Supports object & OOP C (++ is the increment

    operator)

    JAVA SupportsWeb programming Originally named Oak

    Origin of Name

  • 8/3/2019 t 01 b Computer Intro Languages

    7/16

    Semantic GapSemantic Gap

    A semantic gap exists between theA semantic gap exists between theamount of information conveyed inamount of information conveyed in

    assembly language v high levelassembly language v high level

    languages. Consider the following Clanguages. Consider the following Csingle statement:single statement:

    x = x+3;x = x+3;

    This single statement may require manyThis single statement may require many

    assembly language statementsassembly language statements

    (operations):(operations):

    Load memory location24 intoLoad memory location24 intoaccumulatoraccumulator

    Add a constant 3 to theAdd a constant 3 to the

    accumulatoraccumulator

    Store accumulator in memoryStore accumulator in memory

    location24location24

    The number of executable statementThe number of executable statement

    expands greatly during the translationexpands greatly during the translation

    process from a high level language intoprocess from a high level language into

    assembly language.assembly language.

  • 8/3/2019 t 01 b Computer Intro Languages

    8/16

    C Programming LanguageC Programming LanguageC

    HighHigh--level generallevel general--purpose language developed inpurpose language developed in1972 at AT&T Bell Lab. By Dennis Ritchie1972 at AT&T Bell Lab. By Dennis Ritchie from twofrom twoprevious programming BCPL and Bprevious programming BCPL and B

    Originally developed to write the UNIX operatingOriginally developed to write the UNIX operating

    systemsystem

    Hardware 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 areToday, virtually all new operating systems are

    written in C or C++.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,C++ is a more advanced version of C,incorporating among other things, the objectincorporating among other things, the object--

    oriented constructsoriented constructs

    StandardizationStandardizationMany slight variations of C existed, and wereMany slight variations of C existed, and were

    incompatibleincompatibleCommittee formed to create a "unambiguous, machineCommittee formed to create a "unambiguous, machine--

    independent" definitionindependent" definition

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

    C has become a popular language industry due itsC has become a popular language industry due its

    power and flexibilitypower and flexibility

  • 8/3/2019 t 01 b Computer Intro Languages

    9/16

    The C Standard LibraryThe C Standard LibraryC programs consist ofC programs consist ofpieces/modules called functionspieces/modules called functions

    A programmer can create his ownA programmer can create his ownfunctionsfunctions

    Advantage: the programmer knowsAdvantage: the programmer knowsexactly how it worksexactly how it works

    Disadvantage: time consumingDisadvantage: time consuming

    Programmers will often use the CProgrammers will often use the Clibrary functionslibrary functions

    Use these as building blocksUse these as building blocks

    Avoid reAvoid re--inventing the wheelinventing the wheelIf a preIf a pre--made function exists, generallymade function exists, generallybest to use it rather than write your ownbest to use it rather than write your own

    Library functions carefully written,Library functions carefully written,efficient, and portableefficient, and portable

  • 8/3/2019 t 01 b Computer Intro Languages

    10/16

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

    The Key Software Trend: ObjectsThe Key Software Trend: Objectsin C++ and JAVAin C++ and JAVA

    Reusable software components thatReusable software components that

    model items in the real worldmodel items in the real world

    Meaningful software units: ex:Meaningful software units: ex: Date objects,Date objects,time objects, audio objects, video objects, filetime objects, audio objects, video objects, file

    objects, record objectsaobjects, record objectsany noun can beny noun can be

    represented as an objectrepresented as an object

    More understandable, better organized,More understandable, better organized,and easier to maintain than proceduraland easier to maintain than procedural

    programmingprogramming

    Favor modularityFavor modularity

  • 8/3/2019 t 01 b Computer Intro Languages

    11/16

    The C Standard LibraryThe C Standard Library

    #include #include

    main()main()

    {{int i;int i;

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

    {{

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

    }}

    }}

  • 8/3/2019 t 01 b Computer Intro Languages

    12/16

    A Typical C Program DevelopmentA Typical C Program Development

    EnvironmentEnvironment

    1.1. EditEdit

    2.Preprocess2.Preprocess

    3.3. CompileCompile

    4.4. LinkLink

    5.5. LoadLoad

    6.6. ExecuteExecute

    Disk

    Disk

    Loader

    Linker

    Compiler

    Preprocessor

    Editor

    Disk

    Disk

    Disk

    Primary Memory

    CP

    U

    Primary Memory

    1. Program is created in

    the editor and stored on

    disk2. Preprocessor

    program processes

    the code3. 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:

  • 8/3/2019 t 01 b Computer Intro Languages

    13/16

    A Typical C Program DevelopmentA Typical C Program Development

    EnvironmentEnvironment (cont.)(cont.)

    Procedure to Prepare a C Program for ExecutionProcedure to Prepare a C Program for Execution

    Enter the program code and

    save as a source (*.c) file

    using Word Processor

    (editor)

    The linker linksthe 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)

    Revised

    source file

    New object

    (*.obj) files

    (Format: binary)

    Executable

    (*.exe, *.out) file

    (Format: binary)Welcome to

    CSCI230

    Other object

    (*.obj) files

    Correct

    syntaxerrors

    List of errors

    Compiler attempts totranslate the

    program

    into machine code

    Input

    data

    Results

  • 8/3/2019 t 01 b Computer Intro Languages

    14/16

    Constructs in C LanguageConstructs in C Language

    Type Declarations:Type Declarations: ex:ex: int, float,

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

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

  • 8/3/2019 t 01 b Computer Intro Languages

    15/16

  • 8/3/2019 t 01 b Computer Intro Languages

    16/16

    Application SoftwareApplication SoftwareDeveloped to assist a computerDeveloped to assist a computer

    user in accomplishing specialuser in accomplishing specialtaskstasks

    ex: word processing applications:ex: word processing applications:MSMS--word or Wordword or Word--perfectperfect

    ex: Spreadsheet applications:ex: Spreadsheet applications:Lotus1Lotus1--22--3, Excel3, Excel

    ex: Database: Oracle, MSex: Database: Oracle, MS--AccessAccess

    Software Development LifeSoftware Development LifeCycle (SDLC)Cycle (SDLC)

    ProblemProblem: specify the problem: specify the problemrequirementsrequirements

    AnalysisAnalysis: analyze the problem: analyze the problem

    DesignDesign: design the algorithm to: design the algorithm to

    solve the problemsolve the problemImplementationImplementation: Implement the: Implement thealgorithmalgorithm

    TestingTesting: test and verify the: test and verify thecompleted programcompleted program

    MaintenanceMaintenance: maintain and update: maintain and updatethe programthe program