1 / 29

Chapter 1.4

Chapter 1.4. Programming Languages and Programming. Machine Language vs. Assembler. Machine Language Assembler P1: 10 0 1 COPY #0 ND P2: 10 0 2 COPY #0 SC P3: 40 11 0 3 EQ? KFL #0 P3 P4: 24 2 10 2 MUL SC #10 SC P5: 21 2 12 2 ADD SC KDA SC P6: 10 0 11 COPY #0 KFL

caronlee
Download Presentation

Chapter 1.4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 1.4 Programming Languages and Programming

  2. Machine Language vs. Assembler Machine LanguageAssembler P1:10 0 1 COPY #0 ND P2:10 0 2 COPY #0 SC P3:40 11 0 3 EQ? KFL #0 P3 P4:24 2 10 2 MUL SC #10 SC P5:21 2 12 2 ADD SC KDA SC P6:10 0 11 COPY #0 KFL P7:20 1 1 1 ADD ND #1 ND P8:42 1 3 3 NE? ND #3 P3 P9:42 2 321 1 NE? SC #321 P1 P10:10 1 13 COPY #1 DDA P11:47 1 JMP P1

  3. Assembler Example ND: DAT 2 Number of digits,2 bytes SC: DAT 2 Secret code,2 bytes KFL: EQU 10 Keyboard Flag KDA: EQU 11 Keyboard Data DDA: EQU 13 Door Data BGN: COPY #0 ND Init. number of digits COPY #0 SC Init. secret code TFL: EQ? KFL #0 TFL Test for key stroke MUL SC #10 SC Shift SC one digit left ADD SC KDA SC Add new digit to SC COPY #0 KFL Reset keyflag ADD ND #1 ND Increase entered digits NE? ND #3 TFL More digits needed ? NE? SC #321 BGN Correct secret code ? COPY #1 DDA Open the door JMP BGN Restart everything END

  4. The ASSEMBLER Source Code (LLL) ASSEMBLER Object Code HARDWARE

  5. ABL Assembling and Executing 1. Loading the Assembler Assembler (in machine language)

  6. Assembling and Executing 2. Assembling the program Source Code Object Code Assembler

  7. Assembling and Executing 3. Loading the user’s program ABL User’s Program (in machine language)

  8. Assembling and Executing 4. Executing the user’s program User’s Data User’s results User’s Program

  9. Assembler Example ND: DAT 2 Number of digits,2 bytes SC: DAT 2 Secret code,2 bytes KFL: EQU 10 Keyboard Flag KDA: EQU 11 Keyboard Data DDA: EQU 13 Door Data BGN: COPY #0 ND Init. number of digits COPY #0 SC Init. secret code TFL: EQ? KFL #0 TFL Test for key stroke MUL SC #10 SC Shift SC one digit left ADD SC KDA SC Add new digit to SC COPY #0 KFL Reset keyflag ADD ND #1 ND Increase entered digits NE? ND #3 TFL More digits needed ? NE? SC #321 BGN Correct secret code ? COPY #1 DDA Open the door JMP BGN Restart everything END

  10. High-level Language Example VAR ND,SC : CARDINAL; KFL[10] : (idle,ready); KDA[11] : [0..9]; DDA[13] : (closed,open); BEGIN LOOP SC := 0; FOR ND := 1 TO 3 DO REPEAT UNTIL KFL = ready; SC := SC * 10 + KDA; KFL := idle; END (* FOR *); IF SC = 321 THEN DDA := open END (* IF *) END (* LOOP *) END

  11. STO ADD SHR STO Written A A Oral A A 1 A Final High-vs. Low-Level Languages Final := (Written + Oral) DIV 2

  12. 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. Programming Languages

  13. Source Code (HLL) COMPILER Object Code INTERPRETER HARDWARE

  14. 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 Compilers vs. Interpreters

  15. ABL Compiling and Executing 1. Loading the Compiler Compiler (in machine language)

  16. Compiling and Executing 2. Compiling the program Source Code Object Code Compiler

  17. Compiling and Executing 3. Loading the user’s program ABL User’s Program (in machine language)

  18. Compiling and Executing 4. Executing the user’s program User’s Data User’s results User’s Program

  19. ABL Interpretation 1. Loading the Interpreter Interpreter (in machine language)

  20. Interpretation 2. Interpreting the user’s program Source Code + User’s Data User’s results Interpreter

  21. COMPILER Object Code Source Code (HLL) Assembler Source ASSEMBLER INTERPRETER HARDWARE

  22. COMPILER INTERPRETER 1 INTERPRETER 2 HARDWARE 1 HARDWARE 2 Source Code (HLL) Common Assembler Source

  23. Role of a Linker Source A Source B Source C Source D Compiler X Compiler Y Assembler Reloc. A Reloc. B Reloc. C Reloc. D LINKER Object Code A+B+C+D

  24. 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 Relocatable Code

  25. COMPILER Object Code Source Code (HLL) Reloc.Code LINKER INTERPRETER HARDWARE

  26. 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 under MS/Windows Dynamic Linking

  27. Imperative Program states how things should be done Traditional programming style Efficient execution, often compiled. Non imperative (Declarative or Functional) Program states what should be done Innovative programming style for specific fields Often interpreted. Imperative vs. Non-imperative

  28. READ (Oral); READ (Written); Final := (Oral+Written)/2; WRITE (Final) Declarations: Oral can be read Written can be read Final = (Oral+Written)/2 Commands: Write(Final) Imperative vs. Non-imperative

  29. Spreadsheet example

More Related