Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 1 Chapitre 1.4 Langages et outils de programmation."— Presentation transcript:

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

2 ©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

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

4 ©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

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

6 ©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

7 ©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

8 ©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)

9 ©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

10 ©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

11 ©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

12 ©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

13 ©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

14 ©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

15 ©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.

16 ©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.

17 ©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)

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

19 ©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

20 ©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

21 ©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

22 ©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)

23 ©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

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

25 ©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

26 ©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

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

28 ©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

29 ©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

30 ©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

31 ©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

32 ©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

33 ©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

34 ©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

35 ©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

36 ©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

37 ©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

38 ©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.

39 ©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

40 ©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

41 ©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

42 ©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;

43 ©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.

44 ©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 …

45 ©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

46 ©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

47 ©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

48 ©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 !!!

49 ©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

50 ©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 !

51 ©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

52 ©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

53 ©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

54 ©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;

55 ©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

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

57 ©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

58 ©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)

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


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

Similar presentations


Ads by Google