Presentation is loading. Please wait.

Presentation is loading. Please wait.

CC410: System Programming

Similar presentations


Presentation on theme: "CC410: System Programming"— Presentation transcript:

1 CC410: System Programming
Dr. Manal Helal – Fall 2014 – Lecture 13– Compilers 2

2 Chapter 5 - Compilers Optimization (optional) Source program
Intermediate code generator (semantic analyzer) Code generator Lexical analizer Syntax analizer Intermediate code Lexical units (Tokens) Machine language Parse trees Computer Symbol table

3 Code Generation Add S(id) to LIST and LISTCOUNT++

4 Code Generation (cont’d.)

5 Code Generation (cont’d.)

6 Code Generation (cont’d.)
Save to Register A 1. <term>2 already in Register A, or 2. <factor> already in Register A, or 3. <term>2 and <factor>both are not in Register A

7 Code Generation (cont’d.)
Node Specifier S(<term>1) save to rA

8

9 Code Generation (cont’d.)

10 Code Generation (cont’d.) 9 and 10
S(<exp>) := S(<term>) S(<exp>) <> rA =S(MEAN)

11 Code Generation (cont’d.) 10

12 Code Generation (cont’d.) 10
S(<exp>2) <> rA Call GETA(<exp>2) Generate [SUB S(MEAN)=T2] S(<exp>1) := rA REGA := <exp>1

13 Code Generation (cont’d.) 11
S(<term>) := S(SUMSQ) S(<term>) <> rA S(<term>) := S(MEAN)

14 Code Generation (cont’d.) 11
S(<term>2) <> rA S(<factor>) <> rA Call GETA(MEAN) Generate [MUL MEAN] S(MEAN) := rA REGA:= MEAN

15 Code Generation (cont’d.) 11
S(<term>2) <> rA Call GETA(SUMSQ) Generate [DIV #100] S(<term>1) := rA REGA := <term>1

16 Code Generation (cont’d.) 12
S(<factor>) := S(SUMSQ) S(<factor>) := S(MEAN) S(<factor>) := S(#100)

17 Code Generation (cont’d.)
REGA <> NULL = SUMSQ S(MEAN) <> rA = S(SUMSQ) Generate [STA T1] S(SUMSQ) = T1 Generate [LDA MEAN] S(MEAN) := rA REGA := MEAN REGA = NULL Generate [LDA SUMSQ] S(SUMSQ) := rA REGA := SUMSQ REGA <> NULL = MEAN S(SUMSQ) <> rA = S(MEAN) Generate [STA T2] S(MEAN) = T2 Generate [LDA S(SUMSQ)=T1] S(SUMSQ) := rA REGA := SUMSQ

18 Code Generation (cont’d.)

19 Code Generation (cont’d.) 1, 2, and 3

20 Code Generation (cont’d.) 4, 5, and 7

21 8, 14, 15

22 Code Generation (cont’d.) 16 and 17

23 Code Generation (cont’d.)

24 Code Generation (cont’d.)


Download ppt "CC410: System Programming"

Similar presentations


Ads by Google