Chapitre 1'4 - PowerPoint PPT Presentation

1 / 59
About This Presentation
Title:

Chapitre 1'4

Description:

Chapitre 1'4 – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 60
Provided by: infowe
Category:
Tags: chapitre | tfl

less

Transcript and Presenter's Notes

Title: Chapitre 1'4


1
Chapitre 1.4
  • Langages et outils
  • de programmation

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
Machine Language vs. Assembler
Machine Language Assembler P1 10 0 101 CO
PY 0 ND P2 10 0 102 COPY 0 SC P3 40 200 0 3
EQ? KFL 0 P3 P4 24 102 10 102 MUL SC 10 SC P5
21 102 201 102 ADD SC KDA SC P6 10 0 200 COPY
0 KFL P7 20 101 1 101 ADD ND 1 ND P8 42 101 3
3 NE? ND 3 P3 P9 42 102 321 1 NE? SC 321 P1 P10
10 1 202 COPY 1 DDA P11 47 1 JMP P1
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
The ASSEMBLER
Source Code (LLL)
ASSEMBLER
Object Code
HARDWARE
6
Assembling and Executing
1. Loading the Assembler
Assembler (in machine language)
7
Assembling and Executing
2. Assembling the program
Source Code
Object Code
Assembler
8
Assembling and Executing
3. Loading the users program
ABL
Users Program (in machine language)
9
Assembling and Executing
4. Executing the users program
Users Data
Users results
Users Program
10
Assembly LanguageSource Code Format
Label Opc Operands Comments BGN COPY 0,N
D Initialise number of entered
digits COPY 0,SC Initialise secret
code TFL EQ? KFL,0,TFL Test continuously for
key stroke MUL SC,10,SC Shift SC one digit to
the left ADD SC,KDA,SC Add newly entered digit
to SC COPY 0,KFL Reset Keyboard
flag ADD ND,1,ND Increase number of entered
digits NE? ND,3,TFL Any more digits needed
? NE? SC,321,BGN Is the entered secret code
correct ? COPY 1,DDA Open the
door JMP BGN Restart everything
11
Assembly LanguagePseudo Instructions
Label Opc Operands Comments ORG 100 First
address of data memory ND DAT 2 Number of
entered digits, 2 bytes SC DAT 2 Secret Code
as entered, 2 bytes KFL EQU 200 Keyboard flag,
hardwired at address 200 KDA EQU KFL1 Keyboard
data DDA EQU 202 Door data ORG 0 First
address of program memory END
12
WHAT IS A PROGRAM ?
PROGRAM Description of data Actions to
perform upon these data
13
Assembler Example
ORG 100 Begin of data memory ND DAT 2 Number
of digits,2 bytes SC DAT 2 Secret code,2
bytes KFL EQU 200 Keyboard Flag KDA EQU 201
Keyboard Data DDA EQU 202 Door
Data ORG 0 Begin of program memory 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 Incre
ase 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
14
High-level Language Example
VAR ( data ) ND,SC
INTEGER KFL200 (idle,ready) ( Keyboard
flag ) KDA201 0..9 ( Keyboard
data ) DDA202 (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
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
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
Imperative vs. Non-imperative
  • READ (archi)
  • READ (algo)
  • final (archialgo)/2
  • WRITE (final)
  • Declarations
  • archi can be read
  • algo can be read
  • final (archialgo)/2
  • Commands
  • Write(final)

18
Spreadsheet example
19
Compilers vs. Interpreters
Translates and executes Statement after
Statement
20
Compiling and Executing
1. Loading the Compiler
Compiler (in machine language)
21
Compiling and Executing
2. Compiling the program
Source Code
Object Code
Compiler
22
Compiling and Executing
3. Loading the users program
ABL
Users Program (in machine language)
23
Compiling and Executing
4. Executing the users program
Users Data
Users results
Users Program
24
Interpretation
1. Loading the Interpreter
Interpreter (in machine language)
25
Interpretation
2. Interpreting the users program
Source Code
Users results
Users Data
Interpreter
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
Source Code (HLL)
Assembler Source
ASSEMBLER
INTERPRETER
HARDWARE
28
Source Code (Java)
Common Assembler Source
Java byte code
29
Role of a Linker
Source B
Source C
Source D
Source A
Compiler X
Compiler Y
Assembler
Reloc. D
Reloc. A
Reloc. B
Reloc. C
LINKER
Object Code ABCD
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
LinkersUsing intermediate code
Reloc.A
Main module
Libraries
Reloc.B
LINKER
Reloc.C
Reloc.D
Object
32
Static linking
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
The Cost of Softwarefor successful large systems
During design and coding, efforts should be
made to reduce the cost of debugging and
maintenance
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
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
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
Repairing a flat tireData 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
Repairing a flat tireTop level design of actions
  • inspect the spare wheel
  • if available in good condition,
  • repair yourself
  • else, you will need to call help

40
Repairing a flat tireRefinement of repair
yourself
  • fetch the tools
  • fetch the spare wheel
  • exchange defective and spare wheels
  • store defective wheel
  • store tools

41
Repairing a flat tireRefinement of tools
  • Tools
  • jack device to lift a car
  • wrench device to loose or fasten bolts

42
Repairing a flat tireRefinement 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
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
Repairing a flat tireObject-oriented style
Repairing your flat tire Fetch YourJack Inspect
YourJack if (ok) with YourJack Lift YourCar
with YourJack Lower YourCar Store YourJack
  • Instance of the object
  • YourJack
  • Possible actions
  • Fetch
  • Inspect
  • Store
  • Lift a car
  • Lower a car

Object Jack
45
Repairing a flat tireDecision Table
OK
Not OK
Spare Wheel
Tools
Available OK
repair yourself
get help
No good tools available
get help
try to borrow tools
46
Repairing a flat tireTop-level Controlflowchart
Yes
No
47
Repairing a flat tireRefinement of repair
yourself
spare wheel OK ?
No
Yes
get help
repair yourself
48
Repairing a flat tireRefinement of get tools
tools present OK ?
No
Yes
try borrowing tools
got tools or tired ?
pick up the tools
No
Yes
tools present OK ?
Yes
No
Help Needed !!!
49
Repairing a flat tireAdapted refinement of get
tools
tools present OK ?
No
Yes
try borrowing tools
got tools or tired ?
pick up the tools
No
Yes
50
Repairing a flat tireImproved top-level design
Risk Spaghetti Programming !
51
State DiagramsFlat tire problem
52
State DiagramsElectronic lock
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
Assignment Statement
area pi radius radius
  • 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

55
Selection Statement
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
No
Tasks to be done if no criteria OK
56
if (B) S1 else S2
57
Iteration Statement
Initialization
Loopbody, part 1
Termination Test
Finish
Continue
Loopbody, part 2
58
while (B) S
do S while (B)
S
B
TRUE
FALSE
59
Function Call Statement
Write a Comment
User Comments (0)
About PowerShow.com