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

Slides:



Advertisements
Similar presentations
The University of Adelaide, School of Computer Science
Advertisements

Compiler Construction Sohail Aslam Lecture ExampleExample a = b + c t1 = a * a b = t1 + a c = t1 * b t2 = c + b a = t2 + t2.
10/6: Lecture Topics Procedure call Calling conventions The stack
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
The University of Adelaide, School of Computer Science
Subprogram Control - Data sharing Mechanisms to exchange data Arguments - data objects sent to a subprogram to be processed. Obtained through  parameters.
UNIT-III By Mr. M. V. Nikum (B.E.I.T). Programming Language Lexical and Syntactic features of a programming Language are specified by its grammar Language:-
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
1 System Programming System Software, pp Chia-Hui Chang, Assistant Professor Dept. of Computer Science & Information Engineering National Central.
System Software by Leland L. Beck chapter 1, pp.1-20.
System Software.
1 Chapter 7: Runtime Environments. int * larger (int a, int b) { if (a > b) return &a; //wrong else return &b; //wrong } int * larger (int *a, int *b)
ISBN Chapter 10 Implementing Subprograms –Semantics of Calls and Returns –Implementing “Simple” Subprograms –Implementing Subprograms with.
1 CSCI 360 Survey Of Programming Languages 9 – Implementing Subprograms Spring, 2008 Doug L Hoffman, PhD.
Chih-Hung Wang Chapter 1: Background (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
Compilers -- Basic functions
5.3 Machine-Independent Compiler Features
ISBN Chapter 10 Implementing Subprograms.
A Simple Two-Pass Assembler
Instruction Selection II CS 671 February 26, 2008.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Runtime Environments Compiler Construction Chapter 7.
CSc 453 Runtime Environments Saumya Debray The University of Arizona Tucson.
Functions and Procedures. Function or Procedure u A separate piece of code u Possibly separately compiled u Located at some address in the memory used.
CPSC 388 – Compiler Design and Construction Runtime Environments.
Runtime Environments. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
CHAPTER 5 Compiler 5.1 Basic Compiler Concepts. Basic Compiler Concepts 1. Lexical Analysis (Lexical Analyzer 或 Scanner) Read the source program one character.
Syntactic Analysis Operator-Precedence Parsing Recursive-Descent Parsing.
COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent.
國立台灣大學 資訊工程學系 薛智文 98 Spring Run Time Environments (textbook ch# 7.1–7.3 )
GPRS Part II Wireless and Mobile Network Architecture
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
10-1 Chapter 10: Implementing Subprograms The General Semantics of Calls and Returns Implementing “Simple” Subprograms Implementing Subprograms with Stack-Dynamic.
ISBN Chapter 10 Implementing Subprograms.
Implementing Subprograms
Int main( ) { x = a(); } int a() { y = b(); } int b() { z = c(); } int c() { } 1.
ISBN Chapter 10 Implementing Subprograms.
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Compiler Summary Lexical analysis—scanner – String of characters  token – Finite automata. Syntactical analysis – parser – Sequence of tokens –> language.
Implementing Subprograms
Run-time support Jakub Yaghob
Implementing Subprograms
Overview of Instruction Set Architectures
Procedures (Functions)
Procedures (Functions)
Functions and Procedures
Implementing Subprograms
Programming Languages (CS 550) Mini Language Compiler
Implementing Subprograms
The University of Adelaide, School of Computer Science
CC410: System Programming
Linked Lists Chapter 4.
THE FETCH-EXECUTE CYCLE.
A Simple Two-Pass Assembler
UNIT V Run Time Environments.
Data Hazard Example (no stalls).
Computer Architecture
THE FETCH-EXECUTE CYCLE.
Programming Languages (CS 360) Mini Language Compiler
Run-time environments
Implementing Subprograms
Topic 2b ISA Support for High-Level Languages
Code Optimization.
Presentation transcript:

1 Code Generation (cont’d.)

2 Save to Register A 1. 2 already in Register A, or 2. already in Register A, or 3. 2 and both are not in Register A

3 Code Generation (cont’d.) Node Specifier S( 1 ) save to rA

4

5 Code Generation (cont’d.)

6

7 Code Generation (cont’d.) 9 and 10 S( ) := S( ) = S(SUMSQ) REGA = S( ) <> rA =S(MEAN)

8 Code Generation (cont’d.) 10

9 S( 2 ) <> rA = S(MEAN) Call GETA( 2 ) GETA(SUMSQ) Generate [SUB S(MEAN)=T2] S( 1 ) := rA REGA := 1

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

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

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

13 Code Generation (cont’d.) 12 S( ) := S(SUMSQ) S( ) := S(MEAN l ) S( ) := S(MEAN r ) S( ) := S(#100)

14

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

16 Code Generation (cont’d.) I

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

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

19 8, 14, 15

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

21 Code Generation (cont’d.)

22 Code Generation (cont’d.)

23

24

25

26

27

28

29

30

31 LDASUMSQ DIV#100 STAT1 LDAMEAN MULMEAN STAT2 LDAT1 SUBT2 STAT3 LDAT3 STAVARIANCE

32 T2 LDAMEAN MULMEAN STAT2 LDASUMSQ DIV#100 STAT1 LDAT1 SUBT2 STAT3 LDAT3 STAVARIANCE

33 T2

34

35

36

37 3*(6-1)=3*5=15

38

39 3*(I-1) Content of Address of A A(3*(I-1))=5

40

41 3*((I-0)*(6-1+1)+(J-1))=5

42 3*((I-1)*(10-1+1)+(2J-1-1)) 3*(i1(i8)*10 3*(i2(i9) +i3(i10)-1-1 +i4(i11)-1 +i5 3*i6(i12) i7(i13)

43

44

45

46 Machine-Independent Compiler Features

47 Machine-Independent Compiler Features Storage Allocation Static Allocation: cannot be used for recursive call Dynamic Allocation: Activation Record

48

49

50

51

52

53

54

55 P-Code Compliers

56 Compiler-Compilers

57