©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 1 Chapitre 1.4 Langages et outils de programmation.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Systems Software.
Introduction to Programming
زبانهای برنامه سازی برنامه سازی پیشرفته ارائه دهنده دکتر سيد امين حسيني E.mail: Home page:
COSC 120 Computer Programming
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 1, Lab.
Program Development and Programming Languages
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
Chapter 1 Program Design
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Chapter 8: Introduction to High-Level Language Programming Invitation to Computer Science, C++ Version, Fourth Edition.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Introduction to Computers and Programming
Chapter 2.1 Program Design and Documentation. Summary System/Program specifications System/Program design –Top-down & Bottom-up design –Object Oriented.
Python quick start guide
Introduction to High-Level Language Programming
Programming Languages: Telling the Computers What to Do Chapter 16.
Chapter 2.3 Modula 2 An Introduction. Summary First example Terminal symbols Comments Data –Constants –Variables Actions –Assignment statement –Control.
Structured COBOL Programming, Stern & Stern, 9th edition
1 Shawlands Academy Higher Computing Software Development Unit.
Systems Software & Operating systems
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Programming. What is a Program ? Sets of instructions that get the computer to do something Instructions are translated, eventually, to machine language.
©J.Tiberghien - ULB-VUB Version Troisième Partie Chapitre 1 Les supports à la programmation.
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
CPS120 Introduction to Computer Programming The Programming Process.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
The Programming Process Define the problem* Make or buy software? Design the program * Code (write) the program Test (debug) the program Document the.
Introduction to Computer Application (IC) MH Room 517 Time : 7:00-9:30pm.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Chapter 1.4 Programming Languages and Programming.
L ECTURE -9 Topics : Compiler Interpreter Loader Linker. Types of Software..
The Software Development Process
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Getting ready. Why C? Design Features – Efficiency (C programs tend to be compact and to run quickly.) – Portability (C programs written on one system.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
INTRODUCTION TO COMPUTER PROGRAMMING(IT-303) Basics.
Hello world !!! ASCII representation of hello.c.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Introduction To Software Development Environment.
Chapter Goals Describe the application development process and the role of methodologies, models, and tools Compare and contrast programming language generations.
Chapter 10 Application Development
Component 1.6.
Component 1.6.
Key Ideas from day 1 slides
Compiler Construction (CS-636)
Ch. 7 Programming Languages
Assembler Design Options
Chapter 1 Introduction(1.1)
CMP 131 Introduction to Computer Programming
The Programming Process
ICT Gaming Lesson 2.
WJEC GCSE Computer Science
Presentation transcript:

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 1 Chapitre 1.4 Langages et outils de programmation

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 2 Summary Programming languages –Low level languages and assemblers –High level languages Imperative and non-imperative languages Tools for executing high level languages System and Program design –Specifications –Design –Tools for design and documentation Essential constructs in imperative languages

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 3 Machine Language Assembler P1:100101COPY#0ND P2:100102COPY#0SC P3: EQ?KFL#0P3 P4: MULSC#10SC P5: ADDSCKDASC P6:100200COPY#0KFL P7: ADDND#1ND P8: NE?ND#3P3 P9: NE?SC#321P1 P10:101202COPY#1DDA P11:471JMPP1 Machine Language vs. Assembler

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 4 Machine vs. Assembly language Data memory addresses receive symbolic names. Program memory addresses receive symbolic names. IO interfaces receive symbolic names. Operation codes receive a name that evokes the performed action. each machine instruction corresponds to one assembly language instruction An assembly language program can have pseudo instructions which are commands for the assembler

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 5 Source Code (LLL) ASSEMBLER Object Code HARDWARE The ASSEMBLER

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 6 Assembling and Executing 1. Loading the Assembler Assembler (in machine language) ABL

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 7 Assembling and Executing 2. Assembling the program Assembler Source Code Object Code

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 8 Assembling and Executing 3. Loading the user’s program ABL User’s Program (in machine language)

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 9 Assembling and Executing 4. Executing the user’s program User’s Program User’s Data User’s results

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 10 Assembly Language Source Code Format Label Opc Operands Comments BGN:COPY#0,NDInitialise number of entered digits COPY#0,SCInitialise secret code TFL:EQ?KFL,#0,TFLTest continuously for key stroke MULSC,#10,SCShift SC one digit to the left ADDSC,KDA,SCAdd newly entered digit to SC COPY#0,KFLReset Keyboard flag ADDND,#1,NDIncrease number of entered digits NE?ND,#3,TFLAny more digits needed ? NE?SC,#321,BGNIs the entered secret code correct ? COPY#1,DDAOpen the door JMPBGNRestart everything

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 11 Assembly Language Pseudo Instructions Label OpcOperandsComments ORG100First address of data memory ND:DAT2Number of entered digits, 2 bytes SC:DAT2Secret Code as entered, 2 bytes KFL:EQU200Keyboard flag, hardwired at address 200 KDA:EQUKFL+1Keyboard data DDA:EQU202Door data ORG0First address of program memory … END

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 12 WHAT IS A PROGRAM ? PROGRAM = Description of data + Actions to perform upon these data

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 13 ORG100Begin of data memory ND:DAT2Number of digits,2 bytes SC:DAT2Secret code,2 bytes KFL:EQU200Keyboard Flag KDA:EQU201Keyboard Data DDA: EQU202Door Data ORG0Begin of program memory BGN:COPY#0NDInit. number of digits COPY#0SCInit. secret code TFL:EQ?KFL#0TFLTest for key stroke MULSC#10SCShift SC one digit left ADDSCKDASCAdd new digit to SC COPY#0KFLReset keyflag ADDND#1NDIncrease entered digits NE?ND#3TFLMore digits needed ? NE?SC#321BGNCorrect secret code ? COPY#1DDAOpen the door JMPBGNRestart everything END Assembler Example

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 14 VAR (* data *) ND,SC : INTEGER; KFL[200] : (idle,ready); (* Keyboard flag *) KDA[201] : [0..9]; (* Keyboard data *) DDA[202] : (closed,open); (* Door data *) BEGIN (* actions *) LOOP SC := 0; FOR ND := 1 TO 3 DO REPEAT UNTIL KFL = ready; SC := SC * 10 + KDA; KFL := idle; END (* Key reading FOR *); IF SC = 321 THEN DDA := open END (* Key test IF *) END (* ever running LOOP *) END High-level Language Example

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 15 Programming Languages Low Level Languages (Assembler) –One statement corresponds to one instruction –Machine specific –Error prone, low programmers productivity High Level Languages –One statement corresponds to many instructions –Machine independent –User friendly, high programmers productivity.

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 16 Imperative vs. Non-imperative Imperative –Program states how things should be done –Traditional programming style –Efficient execution. Non imperative (Declarative or Functional) –Program states what should be done –Innovative programming style for specific fields –Often rather slow.

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 17 Imperative vs. Non-imperative READ (archi); READ (algo); final := (archi+algo)/2; WRITE (final) Declarations: archi can be read algo can be read final = (archi+algo)/2 Commands: Write(final)

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 18 Spreadsheet example

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 19 Translates and executes Statement after Statement HARDWARE INTERPRETER Source Code (HLL) COMPILER Object Code Translates the entire program at once Compilers vs. Interpreters

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 20 Compiling and Executing 1. Loading the Compiler Compiler (in machine language) ABL

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 21 Compiling and Executing 2. Compiling the program Compiler Source Code Object Code

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 22 Compiling and Executing 3. Loading the user’s program ABL User’s Program (in machine language)

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 23 Compiling and Executing 4. Executing the user’s program User’s Program User’s Data User’s results

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 24 Interpretation 1. Loading the Interpreter Interpreter (in machine language) ABL

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 25 Interpretation 2. Interpreting the user’s program Interpreter User’s results Source Code + User’s Data

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 26 Compilers vs. Interpreters Compilers –Translate the entire program at once –Program execution very fast –Poor run-time error messages Interpreters –Translate and execute statement after statement –Very slow execution –Good run-time error messages

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 27 HARDWARE INTERPRETER Source Code (HLL) COMPILER Object Code ASSEMBLER Assembler Source

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 28 HARDWARE 1 INTERPRETER 1 Source Code (Java) COMPILER Common Assembler Source HARDWARE 2 INTERPRETER 2 Java byte code

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 29 Source BSource CSource DSource A Reloc. DReloc. AReloc. BReloc. C Compiler XCompiler YAssembler LINKER Object Code A+B+C+D Role of a Linker

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 30 Relocatable Code Relocatable object code = three tables: –CODE Program to be loaded from address 0 List of all location dependant addresses –EXTERNALS Symbolic names to be imported Addresses where these externals are referenced –ENTRY POINTS Symbolic names that can be referenced elsewhere Address corresponding to the symbolic name

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 31 Linkers Using intermediate code Reloc.A Object LINKER Reloc.B Reloc.C Reloc.D Main module Libraries

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 32 HARDWARE INTERPRETER Source Code (LLL or HLL) Translator Object Code LINKER Reloc.Code Static linking

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 33 Dynamic Linking Fact : –Many procedures are not activated at each program execution Solution : –Link at run-time ! Initial procedure calls replaced by call to linker Procedure name passed as parameter to linker –Example :.dll files in MS/DOS & Windows

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 34 The Cost of Software for successful large systems During design and coding, efforts should be made to reduce the cost of debugging and maintenance

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 35 Summary Programming languages –Low level languages and assemblers –High level languages Imperative and non-imperative languages Tools for executing high level languages System and Program design –Specifications –Design –Tools for design and documentation Essential constructs in imperative languages

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 36 Design Methods Top-down design: From global to detail –Decompose the problem in simpler subproblems –Further decompose subproblems –UNTIL all subproblems have trivial solutions Bottom-up design: From detail to global –Solve some small problems that might be useful for solving the big problem –Use the partial solutions for assembling a global solution

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 37 Example : Repairing a flat tire Specifications : –Given : A car with a flat tire –Wanted : Instructions for fixing it Strategy choice : –Wait with a smile until somebody fixes it … –Call a repair service >Try to repair yourself

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 38 Repairing a flat tire “Data” and Actions “Data” –Car, Defective wheel, Spare wheel, Tools. Actions –All that need to be done with the Car, the Defective wheel, the Spare wheel and the Tools in order to solve the problem.

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 39 Repairing a flat tire Top level design of actions inspect the spare wheel if available & in good condition, –repair yourself –else, you will need to call help

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 40 Repairing a flat tire Refinement of “repair yourself” fetch the tools fetch the spare wheel exchange defective and spare wheels store defective wheel store tools

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 41 Repairing a flat tire Refinement of “tools” Tools : –jack : device to lift a car –wrench : device to loose or fasten bolts

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 42 Repairing a flat tire Refinement of “Exchange defective and spare wheels” do loose one bolt with wrench while fastened bolts left; lift car with jack; do remove one bolt while bolts left; remove defective wheel; put spare wheel in place; do replace one bolt while bolts missing; lower car with jack; do fasten one bolt with wrench while bolts loose;

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 43 Object oriented Design Problem : –If a data item is slightly changed, the entire program needs to be checked. Solution : –Group data with description of all actions that can be performed upon such data –Access data exclusively through the actions predefined for these data Object = data + actions to access it.

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 44 Repairing a flat tire Object-oriented style Instance of the object : YourJack Possible actions : Fetch = … Inspect = … Store = … Lift a car = … Lower a car = … Object Jack = Repairing your flat tire … Fetch YourJack Inspect YourJack if (ok) … with YourJack Lift YourCar … with YourJack Lower YourCar … Store YourJack …

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 45 Repairing a flat tire Decision Table Spare Wheel Tools Available & OK No good tools available OKNot OK repair yourself get help try to borrow tools

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 46 Repairing a flat tire Top-level Controlflowchart spare wheel OK ? get help repair yourself No Yes

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 47 Repairing a flat tire Refinement of “repair yourself” spare wheel OK ? get help repair yourself NoYes get tools get spare wheel change wheel store bad wheel store tools

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 48 Repairing a flat tire Refinement of “get tools” tools present & OK ? tools present & OK ? pick up the tools try borrowing tools NoYes got tools or tired ? Yes No Help Needed !!!

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 49 Repairing a flat tire Adapted refinement of “get tools” tools present & OK ? pick up the tools try borrowing tools NoYes got tools or tired ? Yes No

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 50 Repairing a flat tire Improved top-level design spare wheel OK ? NoYes tools OK ? fetch tools Yes No get help repair yourself Risk : Spaghetti Programming !

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 51 State Diagrams Flat tire problem Driving Flat tire Need help Good spare wheel Repairing Try borrow tools Puncture No good Spare wheel Successful help No success Spare wheel OK Done No tools Tools OK Success

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 52 State Diagrams Electronic lock First digit entered Waiting 1st digit Testing key Waiting 2nd digit Waiting 3rd digit Second digit entered Third digit entered Wrong Key Opening door Good Key Closing the door by hand

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 53 Summary Programming languages –Low level languages and assemblers –High level languages Imperative and non-imperative languages Tools for executing high level languages System and Program design –Specifications –Design –Tools for design and documentation Essential constructs in imperative languages

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 54 Assignment Statement Assignment operator: in C = (in other languages :=) –The = used for assignment is fundamentally different from the = used in mathematics. –In math, the = sign denotes a timeless relation –In C, the = operator describes a particular action: The right side expression is evaluated Its value is stored in the left side variable –Illustrative example : a = a + 1; area = pi * radius * radius;

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 55 Selection Statement No selector = a ? Tasks to be done if selector = A Yes No selector = b ? Tasks to be done if selector = B Yes No selector = c ? Tasks to be done if selector = C Yes Tasks to be done if no criteria OK

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 56 if (B) S1 else S2; B S2S1 FALSETRUE

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 57 Iteration Statement Termination Test Initialization Loopbody, part 1 Loopbody, part 2 Continue Finish

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 58 while (B) S ; B S TRUE FALSE S B TRUE FALSE do S while (B)

©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 59 Function Call Statement CCC doCCC function DoCCC end DoCCC