Real Time Systems - PowerPoint PPT Presentation

1 / 41
About This Presentation
Title:

Real Time Systems

Description:

J.Tiberghien - ULB-VUB J.Tiberghien - ULB-VUB. Version 2003-2004. 1 ... Macro Expander. Main module. Macro Library. Assembler. Compiler. Expanded Source Code ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 42
Provided by: infowe
Category:
Tags: expander | real | systems | time

less

Transcript and Presenter's Notes

Title: Real Time Systems


1
Troisième Partie Chapitre 1 Les supports à la
programmation
2
Programming languages
Source code
C
High Level Language
Assembler
Low Level Languages
Object code
Machine Language
HARDWARE
3
Machine Language
4
Assembler Language
Label Operation 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 1 Keyboard flag
KDA EQU KFL1 Keyboard data
DDA EQU 3 Door data
ORG 10 First address of program memory
BGN COPY 0,ND 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
END
5
High Level language
Main() int sc 0 const int Key 321 bool
KFL 1 int KDA KFL1 bool DDA 3
while (true) for (int nd1ndlt3nd) while
(KFL 0) sc sc10KDA if (sc
Key) DDA 1
KFL
DDA
KDA
6
Transforming Source Code
7
Translators vs. Interpreters
  • Translators
  • 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

8
Macros
  • 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
  • ...

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

10
Macro Expanders
Source
Main module
Macro Library
Macro Expander
Expanded Source Code
Assembler Compiler
Object
11
Macros vs. Functions
  • FUNCTIONS
  • Dynamic Expansion
  • Save memory space
  • Slow
  • Programmer friendly parameter passing not
    available in assembler
  • MACROS
  • Static Expansion
  • Waste of memory
  • Fast
  • Powerful parameter passing, even in assembler

12
Translating HLLs
13
Syntax and Semantics
  • Syntax form
  • Semantics meaning
  • Example
  • My beer is on the table
  • Syntax OK
  • Semantics OK
  • My table is on the beer
  • Syntax OK
  • Semantics You had too many beers !!!

14
Syntax Definition 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,ltifstat
    ementgt
  • Metalinguistic expression
  • Formal definition () of a non-terminal symbol
  • Contains terminal and non-terminal symbols
  • Expresses juxtaposition or choice (the
    operator)
  • Example ltDigitgt 0123456789

15
BNF Examples (1)
  • ltUpperCaseLettergt ABCDE
    XYZ
  • ltLowerCaseLettergt abcde
    xyz
  • ltLettergt ltUpperCaseLettergt
    ltLowerCaseLettergt
  • ltDigitgt 1234567890
  • ltCardinalNumbergt ltDigitgt ltDigitgtltCardinalNum
    bergt
  • ltIntegerNumbergt ltCardinalNumbergt
  • ltCardinalNumbergt
  • - ltCardinalNumbergt
  • ltIdentifiergt ltLettergt
    ltIdentifiergtltLettergt ltIdentifiergt ltDigitgt

16
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a ltCardinalNumbergt ?
  • Is it a ltDigitgt ?
  • Certainly not

17
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 23 a ltCardinalNumbergt ?

18
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 23 a ltCardinalNumbergt ?
  • Is it a ltDigitgt ?
  • Certainly not

19
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 23 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 3 a ltCardinalNumbergt ?

20
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 23 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 3 a ltCardinalNumbergt ?
  • Is it a ltDigitgt ?
  • YES

21
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 23 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 3 a ltCardinalNumbergt ?
  • Is it a ltDigitgt ?
  • YES
  • As a consequence, 3 is a ltCardinalNumbergt

22
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 23 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 3 a ltCardinalNumbergt ?
  • Is it a ltDigitgt ?
  • YES
  • As a consequence, 3 is a ltCardinalNumbergt
  • As a consequence, 23 is a ltCardinalNumbergt

23
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 23 a ltCardinalNumbergt ?
  • Is it a ltDigitgt followed by a ltCardinalNumbergt ?
  • Is 3 a ltCardinalNumbergt ?
  • Is it a ltDigitgt ?
  • YES
  • As a consequence, 3 is a ltCardinalNumbergt
  • As a consequence, 23 is a ltCardinalNumbergt
  • As a consequence, 123 is a ltCardinalNumbergt

24
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, ...

25
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, ...

26
Syntax Definition
Non-recursive BNF
Syntax diagram
BNF


Definition
Diagram
Choice
0 or 1 occurrence

0, 1 or many occurrences

27
Syntax Definition
Non-recursive BNF
Syntax diagram
BNF


Definition
Diagram
Choice
0 or 1 occurrence

0, 1 or many occurrences

28
BNF Examples (2)
  • ltUpperCaseLettergt ABCDE
    XYZ
  • ltLowerCaseLettergt abcde
    xyz
  • ltLettergt ltUpperCaseLettergt
    ltLowerCaseLettergt
  • ltDigitgt 1234567890
  • ltCardinalNumbergt ltDigitgt ltDigitgt
  • ltIntegerNumbergt -ltCardinalNumbergt
  • ltIdentifiergt ltLettergt ltLettergtltDigitgt

29
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
30
Syntax Definition
Non-recursive BNF
Syntax diagram
BNF


Definition
Diagram
Choice
0 or 1 occurrence

0, 1 or many occurrences

31
Syntax DiagramsExamples
  • Letter

32
Syntax DiagramsExamples
Digit
ltDigitgt 0123456789
CardinalNumber
ltCardinalNumbergt ltDigitgt ltDigitgt
Digit
Digit
33
Syntax DiagramsExamples
IntegerNumber
ltIntegerNumbergt - ltCardinalNumbergt
CardinalNumber
34
Syntax DiagramsExamples
Identifier
ltIdentifiergt ltLettergt ltLettergtltDigitgt
35
The COMPILER
Source Code (HLL)
36
The Lexical Analyzer
  • Recognizes lexical tokens such as
  • Identifiers
  • Numbers
  • -200, 6.3E23,
  • Reserved words
  • for if
  • Multi-character symbols
  • / / ! ...
  • Prepares the symbol table with all identifiers

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

38
Error detection and correction
  • Both the lexical and syntactical analyzer should
    check the source code against syntax errors.
  • When an error has been found, the syntax analyzer
    should
  • generate an error message and stop
  • or
  • generate an error message
  • try to correct by guessing the programmers
    intentions
  • resume the syntax analysis
  • A compiler should never generate any code as long
    as syntax errors are present in the source code,
    even if the syntax analyzer has corrected them in
    order to continue the analysis.

39
Multi-pass compiler
Source
Lexical analysis
Symbol table
Int.1
Syntax analysis
Int.1
Code generation
Int.1
Object
Optimization
40
Single - pass compiler
Source
Symbol table
Object
41
Interpreters
Syntax analysis
Source
Lexical analysis
Symbol table
Simulated code execution
Write a Comment
User Comments (0)
About PowerShow.com