Real Time Systems - PowerPoint PPT Presentation

1 / 83
About This Presentation
Title:

Real Time Systems

Description:

Les supports la programmation Assembling and Executing Assembling and Executing Assembling and Executing Assembling and Executing Machine vs. Assembly language ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 84
Provided by: infowebV
Category:
Tags: linkers | real | systems | time

less

Transcript and Presenter's Notes

Title: Real Time Systems


1
Chapitre 1 Les supports à la programmation
2
Machine Language
3
Low Level Language ( assembler)
4
The ASSEMBLER
Source Code (LLL)
ASSEMBLER
Object Code
HARDWARE
5
Assembling and Executing
1. Loading the Assembler
6
Assembling and Executing
2. Assembling the program
Source Code
Object Code
Assembler
7
Assembling and Executing
3. Loading the users program
ABL
Users Program (in machine language)
8
Assembling and Executing
4. Executing the users program
Users Data
Users results
Users Program
9
Machine vs. Assembly language
  • Variables keep their symbolic name.
  • IO interfaces keep their symbolic name.
  • 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

10
Assembly LanguageSource Code Format
Label Opc Operands Comments BGN STO 0,ND In
itialize digit count STO 0,SC Initialize
entered key KLP EQ? KFL,0,KLP No key pressed
? MUL SC,10,SC Digital left
shift ADD SC,KDA,SC Add new digit STO 0,KFL
Reset keyboard flag ADD ND,1,ND Increment
digit count NE? ND,3,KLP More digits
expected ? NE? SC,321,BGN Wrong code
? STO 1,DDA Open door JMP BGN Restart
11
Machine vs. Assembly language
  • Variables keep their symbolic name.
  • IO interfaces keep their symbolic name.
  • 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

12
Assembly LanguagePseudo Instructions
Label Opc Operands Comments DATA ORG 101 Beg
in of data memory ND BSS 1 Number of
digits SC BSS 1 Entered secret
key KFL EQU 1 Keyboard flag KDA EQU KFL1
Keyboard data DDA EQU 3 Door lock
interface PROG ORG 11 Begin of program
memory ... END
13
Assembly LanguageForward References
WHILE Wvar DO Loopbody END Following part of
program Label Opc Operands Comments WLP EQ?
Wvar,0,Next WHILE test Loop
body ... JMP WLP End of WLP
loop Next ... Following part of program
14
Assemblers
  • One Pass
  • Object code stored in central memory
  • Forward references left open until known
  • Fast but requires lot of memory space
  • Two Pass
  • First pass Symbol table generation
  • Second pass Object code generation
  • Small but slow

15
Two Pass AssemblersReading twice source code
Source
Pass 1
Symbol table
Pass 2
Object
16
Two Pass AssemblersUsing intermediate code
Source
Pass 1
Symbol table
Int.code
Pass 2
Object
17
Variable Length Instructions
  • Instruction length can be function of value of
    operands
  • One pass Assemblers
  • Always maximum length with forward references
  • Request hint from programmer
  • wrong hints result in assembler error message
  • Multi pass assemblers
  • n variable length forward references solved by
    n1 passes.
  • Always maximum length with forward references.
  • Request hint from programmer
  • wrong hints result in assembler error message

18
Macro Assembler
  • LDA 7,U
  • LDB 5,U
  • MUL
  • STD 2,U
  • LDA 6,U
  • LDB 5,U
  • MUL
  • ADD 1,U
  • STD 1,U
  • LDA 6,U
  • LDB 5,U
  • MUL
  • ADD 1,U
  • ...
  • MULB MDEF
  • LDA 1
  • LDB 2
  • MUL
  • MEND
  • MULB 7,U5,U
  • STD 2,U
  • MULB 6,U5,U
  • ADD 1,U
  • STD 1,U
  • MULB 6,U5,U
  • ADD 1,U
  • ...

19
Macros in HLL
  • / The Program / main(void)
  • include one
  • / file one / printf( from 1.\n)
  • include two
  • / file two / printf( from 2.\n)
  • from 1. from 2.

20
Macro Expanders
Source
Main module
Macro Library
Macro Expander
Expanded Source Code
Assembler Compiler
Object
21
Macros vs. Procedures
  • MACROS
  • Static Expansion
  • Waste of memory
  • Fast
  • PROCEDURES
  • Dynamic Expansion
  • Save memory space
  • Slow

22
Role of a Linker
Assembler
LINKER
Object Code ABCD
23
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

24
LinkersUsing intermediate code
Reloc.A
Main module
Libraries
Reloc.B
LINKER
Reloc.C
Reloc.D
Object
25
Two Pass Linkers
Reloc.A
Main module
Libraries
Pass 1
Reloc.B
Module table
Reloc.C
Pass 2
Reloc.D
Object
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 in MS/DOS

27
High Level language
MODULE Lock CONST Key 321 VAR ND
1..3 SC 0..999 KFL1
BOOLEAN KDA2 0..9 DDA3
BOOLEAN BEGIN LOOP SC 0 FOR ND 1 TO
3 DO REPEAT UNTIL KFL SC SC 10
KDA KFL FALSE END ( FOR LOOP ) IF
SC Key THEN DDA TRUE END ( IF )
END ( LOOP ) END Lock
KFL
DDA
KDA
28
Source Code (HLL)
COMPILER
Object Code
INTERPRETER
HARDWARE
29
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

30
The COMPILER
Source Code (HLL)
31
The Lexical Analyzer
  • Recognizes lexical tokens such as
  • numbers
  • -200, 6.3E23,
  • Reserved words
  • for if
  • Multi-character symbols
  • / / ! ...

32
The Syntax Analyzer( syntax parser)
  • Recognizes non-terminal symbols such as
  • a program
  • a variable declaration
  • a procedure declaration
  • an expression
  • Can be generated automatically by a parser
    generator, starting from the BNF syntax
    definitions
  • Represents a program by a syntactical tree.

33
Multi-pass compiler
Source
Lexical analysis
Symbol table
Int.1
Syntax analysis
Int.1
Code generation
Int.1
Object
Optimization
34
Single - pass compiler
Source
Symbol table
Object
35
Backus Naur Formalism (BNF)
  • Terminal Symbols
  • Appear literally in program text
  • Examples a, 3, END, gt,
  • Non-terminal Symbols
  • Name given to set of terminal symbols
  • Written between lt and gt
  • Defined by a metalinguistic expression
  • Examples ltLettergt , ltDigitgt,ltExpressiongt,ltModule
    gt
  • Metalinguistic expression
  • Formal definition () of a non-terminal symbol
  • Contains terminal and non-terminal symbols
  • Expresses juxtaposition or choice (the
    operator)
  • Example ltDigitgt 0123456789

36
Backus Naur Formalism (BNF)Examples
  • ltUpperCaseLettergt ABCDE
    XYZ
  • ltLowerCaseLettergt abcde
    xyz
  • ltLettergt ltUpperCaseLettergt
    ltLowerCaseLettergt
  • ltDigitgt 1234567890
  • ltCardinalNumbergt ltDigitgt ltDigitgtltCardinalNum
    bergt
  • ltIntegerNumbergt ltCardinalNumbergt
  • ltCardinalNumbergt
  • - ltCardinalNumbergt
  • ltIdentifiergt ltLettergt
    ltIdentifiergtltLettergt ltIdentifiergt ltDigitgt

37
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a CardinalNumber ?
  • Is it a digit ?
  • Certainly not

38
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a CardinalNumber ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 23 a Cardinal Number ?

39
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a CardinalNumber ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 23 a Cardinal Number ?
  • Is it a digit ?
  • Certainly not

40
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a CardinalNumber ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 23 a Cardinal Number ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 3 a Cardinal Number ?

41
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a CardinalNumber ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 23 a Cardinal Number ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 3 a Cardinal Number ?
  • Is it a digit ?
  • YES

42
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a CardinalNumber ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 23 a Cardinal Number ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 3 a CardinalNumber ?
  • Is it a digit ?
  • YES
  • As a consequence, 3 is a CardinalNumber

43
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a CardinalNumber ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 23 a Cardinal Number ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 3 a CardinalNumber ?
  • Is it a digit ?
  • YES
  • As a consequence, 3 is a CardinalNumber
  • As a consequence, 23 is a CardinalNumber

44
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a CardinalNumber ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 23 a Cardinal Number ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 3 a CardinalNumber ?
  • Is it a digit ?
  • YES
  • As a consequence, 3 is a CardinalNumber
  • As a consequence, 23 is a CardinalNumber
  • As a consequence, 123 is a CardinalNumber

45
ltIdentifiergt ltLettergt ltIdentifiergtltLettergt
ltIdentifiergt ltDigitgt
  • Correct identifiers
  • Length, Width, Cost, ...
  • MySalary, NumberOfStudents, Year1,
  • X1, Y2, A1, A5,
  • Incorrect identifiers
  • My Salary, Number-of-students,
  • 1stYear, ...

46
Syntax Definition
Non-recursive BNF
Syntax diagram
BNF


Definition
Diagram
Choice
0 or 1 occurrence

0, 1 or many occurrences

47
Syntax Definition
Non-recursive BNF
Syntax diagram
BNF


Definition
Diagram
Choice
0 or 1 occurrence

0, 1 or many occurrences

48
Backus Naur Formalism (BNF)Examples
  • ltUpperCaseLettergt ABCDE
    XYZ
  • ltLowerCaseLettergt abcde
    xyz
  • ltLettergt ltUpperCaseLettergt
    ltLowerCaseLettergt
  • ltDigitgt 1234567890
  • ltCardinalNumbergt ltDigitgt ltDigitgt
  • ltIntegerNumbergt -ltCardinalNumbergt
  • ltIdentifiergt ltLettergt ltLettergtltDigitgt

49
Backus Naur Formalism (BNF)
  • Terminal Symbols
  • Non-terminal Symbols
  • Metalinguistic expression
  • Railroad diagrams with semaphores requiring
    specific symbols to grant passage.
  • The defined non-terminal symbol leaves all its
    symbols, in the order of occurrence, at
    appropriate semaphores and reaches the exit with
    none left.

Terminal symbol
Non-terminal symbol
50
Syntax Definition
Non-recursive BNF
Syntax diagram
BNF


Definition
Diagram
Choice
0 or 1 occurrence

0, 1 or many occurrences

51
Syntax DiagramsExamples
  • Letter

52
Syntax DiagramsExamples
Digit
ltDigitgt 0123456789
CardinalNumber
ltCardinalNumbergt ltDigitgt ltDigitgt
Digit
Digit
53
Syntax DiagramsExamples
IntegerNumber
ltIntegerNumbergt - ltCardinalNumbergt
CardinalNumber
54
Syntax DiagramsExamples
Identifier
ltIdentifiergt ltLettergt ltLettergtltDigitgt
55
Syntax DiagramsExample from the Modula 2 syntax
56
Expression Trees
(ab/c)(d-ef)
For evaluation on a stack machine Postorder
abc/def-
57
Expression Syntax
Expression
Term
Expression

-
Term
Factor
Term

/
Factor
Letter
58
Procedure Expression
Expression
PROCEDURE Expression (VAR p Link) VAR
qLink BEGIN NEW(p)Term(pLeft) IF (Sy
'') OR (Sy '-') THEN p.Op Sy GetSy
Expression(p.Right) ELSE q p p
p.Left DISPOSE(q) END ( IF ) END Expression
59
Procedure Term
Term
PROCEDURE Term (VAR p Link) VAR qLink BEGIN
NEW(p)Factor(pLeft) IF (Sy '') OR (Sy
'/') THEN p.Op Sy GetSy
Term(p.Right) ELSE q p p p.Left
DISPOSE(q) END ( IF ) END Term
60
Procedure Factor
Factor
Letter
PROCEDURE Factor (VAR p Link) BEGIN IF Sy
'(' THEN GetSy Expression(p) GetSy ELSE
NEW(p) p.Op Sy p.Left NIL
p.Right NIL GetSy END ( IF ) END
Factor
61
(ab/c)(d-e/f)
PROCEDURE Expression (VAR p Link) ...
NEW(p)Term(pLeft) ...
Expression
62
(ab/c)(d-e/f)
PROCEDURE Term (VAR p Link) ...
NEW(p)Factor(pLeft) ...
Term Expression
63
(ab/c)(d-e/f).
PROCEDURE Factor (VAR p Link) ... IF Sy '('
THEN GetSy Expression(p) GetSy ...
Factor Term Expression
64
(ab/c)(d-e/f).
PROCEDURE Expression (VAR p Link) ...
NEW(p)Term(pLeft) ...
Expression Factor Term Expression
65
(ab/c)(d-e/f).
PROCEDURE Term (VAR p Link) ...
NEW(p)Factor(pLeft) ...
Term Expression Factor Term Expression
66
(ab/c)(d-e/f)..
PROCEDURE Factor (VAR p Link) ... IF Sy
'(' ... ELSE NEW(p) p.Op Sy
p.Left NIL p.Right NIL GetSy END
( IF ) END Factor
Factor Term Expression Factor Term Expression
67
(ab/c)(d-e/f)..
PROCEDURE Term (VAR p Link) ...
NEW(p)Factor(pLeft) IF (Sy '') OR (Sy
'/') ... ELSE q p p p.Left DISPOSE(q)
END ( IF ) END Term
Term Expression Factor Term Expression
68
(ab/c)(d-e/f)...
PROCEDURE Expression (VAR p Link) ...
NEW(p)Term(pLeft) IF (Sy '') OR (Sy
'-') THEN p.Op Sy GetSy
Expression(p.Right) ...
Expression Factor Term Expression
69
(ab/c)(d-e/f)...
PROCEDURE Expression (VAR p Link) ...
NEW(p)Term(pLeft) ...
Expression Expression Factor Term Expression
70
(ab/c)(d-e/f)...
PROCEDURE Term (VAR p Link) ...
NEW(p)Factor(pLeft) ...
Term Expression Expression Factor Term Expression
71
(ab/c)(d-e/f)....
PROCEDURE Factor (VAR p Link) ... IF Sy
'(' ... ELSE NEW(p) p.Op Sy
p.Left NIL p.Right NIL GetSy END
( IF ) END Factor
Factor Term Expression Expression Factor Term Expr
ession
72
(ab/c)(d-e/f).....
PROCEDURE Term (VAR p Link) ...
NEW(p)Factor(pLeft) IF (Sy '') OR (Sy
'/') THEN p.Op Sy GetSy
Term(p.Right) ...
Term Expression Expression Factor Term Expression
73
(ab/c)(d-e/f).....
PROCEDURE Term (VAR p Link) ...
NEW(p)Factor(pLeft) ...
Term Term Expression Expression Factor Term Expres
sion
74
(ab/c)(d-e/f)......
PROCEDURE Factor (VAR p Link) ... IF Sy
'(' ... ELSE NEW(p) p.Op Sy
p.Left NIL p.Right NIL GetSy END
( IF ) END Factor

Factor Term Term Expression Expression Factor Term
Expression
/
75
(ab/c)(d-e/f)......
PROCEDURE Term (VAR p Link) ...
NEW(p)Factor(pLeft) IF (Sy '') OR (Sy
'/') ... ELSE q p p p.Left DISPOSE(q)
END ( IF ) END Term

Term Term Expression Expression Factor Term Expre
ssion
/
76
(ab/c)(d-e/f)......
PROCEDURE Term (VAR p Link) ... IF THEN
Term(p.Right) ... END ( IF ) END Term

Term Expression Expression Factor Term Expression
/
77
(ab/c)(d-e/f)......
PROCEDURE Expression (VAR p Link) ... IF (Sy
'') OR (Sy '-') ... ELSE q p p
p.Left DISPOSE(q) END ( IF ) END Expression

Expression Expression Factor Term Expression
/
78
(ab/c)(d-e/f)......
PROCEDURE Expression (VAR p Link) ... IF (Sy
'') OR (Sy '-') ... ELSE q p p
p.Left DISPOSE(q) END ( IF ) END Expression

Expression Expression Factor Term Expression
79
(ab/c)(d-e/f)......
PROCEDURE Expression (VAR p Link) ... IF
THEN Expression(p.Right) ... END ( IF
) END Expression

Expression Factor Term Expression
80
(ab/c)(d-e/f).......
PROCEDURE Factor (VAR p Link) ... IF Sy '('
THEN GetSy Expression(p) GetSy END ( IF
) END Factor

Factor Term Expression
81
(ab/c)(d-e/f).......
PROCEDURE Term (VAR p Link) ...
NEW(p)Factor(pLeft) IF (Sy '') OR (Sy
'/') THEN p.Op Sy GetSy
Term(p.Right) ...


Term Expression
82
(ab/c)(d-e/f)........
PROCEDURE Term (VAR p Link) ...
NEW(p)Factor(pLeft) ...


/
Term Term Expression
83
(ab/c)(d-e/f)...............
Write a Comment
User Comments (0)
About PowerShow.com