Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1.4 Programming Languages and Programming.

Similar presentations


Presentation on theme: "Chapter 1.4 Programming Languages and Programming."— Presentation transcript:

1 Chapter 1.4 Programming Languages and Programming

2 Machine Language Assembler P1:1001COPY#0ND P2:1002COPY#0SC P3:401103EQ?KFL#0P3 P4:242102MULSC#10SC P5:212122ADDSCKDASC P6:10011COPY#0KFL P7:20111ADDND#1ND P8:42133NE?ND#3P3 P9:4223211NE?SC#321P1 P10:10113COPY#1DDA P11:471JMPP1 Machine Language vs. Assembler

3 ND:DAT2Number of digits,2 bytes SC:DAT2Secret code,2 bytes KFL:EQU10Keyboard Flag KDA:EQU11Keyboard Data DDA: EQU13Door Data 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

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

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

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

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 Program User’s Data User’s results

9 ND:DAT2Number of digits,2 bytes SC:DAT2Secret code,2 bytes KFL:EQU10Keyboard Flag KDA:EQU11Keyboard Data DDA: EQU13Door Data 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

10 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 High-level Language Example

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

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

13 HARDWARE INTERPRETER Source Code (HLL) COMPILER Object Code

14 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

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

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

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 Program User’s Data User’s results

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

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

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

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

23 Source BSource CSource DSource A Reloc. DReloc. AReloc. BReloc. C Compiler XCompiler YAssembler LINKER Object Code A+B+C+D Role of a Linker

24 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

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

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

27 Imperative vs. Non-imperative 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.

28 Imperative vs. Non-imperative 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)

29 Spreadsheet example


Download ppt "Chapter 1.4 Programming Languages and Programming."

Similar presentations


Ads by Google