CS271 ASSEMBLY LANGUAGE PROGRAMMING - PowerPoint PPT Presentation

1 / 45
About This Presentation
Title:

CS271 ASSEMBLY LANGUAGE PROGRAMMING

Description:

Graduated from the University of Connecticut (05 ... Bachelor of Science from Hanoi University of Technology (86-91) ... Introductory courses at UOP and Devry ... – PowerPoint PPT presentation

Number of Views:60
Avg rating:3.0/5.0
Slides: 46
Provided by: hien2
Category:

less

Transcript and Presenter's Notes

Title: CS271 ASSEMBLY LANGUAGE PROGRAMMING


1
COMPSCI 322 Language and Compilers Class
Hour Hyer Hall 210 TThu 930am 1015am
2
A little bit about the instructor
Assistant professor at UWW since August 2005
  • Graduated from the University of Connecticut (05
    Class), Ph.D in Computer Science and Engineering
  • Master of Computer Science from UW-Milwaukee
    (96-99)
  • Bachelor of Science from Hanoi University of
    Technology (86-91)

3
A little bit about the instructor
  • Research Experience
  • User Modeling, Information Retrieval, Decision
    Theory, Collaborative Filtering, Human Factors
  • Teaching Experience
  • MCS 220, COMPSCI 172, 181, 271, 381 at UWW
  • Introductory courses at UOP and Devry
  • TA for Computer Architecture, OO Design,
    Compiler, Artificial Intelligence

4
Contact information
  • nguyenh_at_uww.edu
  • (fastest way to contact me)
  • Baker Hall 324
  • Office Hours 950am 1050 am, 3-4pm, MWF or by
    appointment
  • 262 472 5170

5
Course Objectives
  • Understand the description and successfully
    design a scanner, parser, semantic checker and
    code generator for this language
  • Implement successfully a scanner, parser,
    semantic checker and code generator for this
    given language. Test the implementation with all
    test cases for each component in a compiler.

6
Book Requirement
  • Engineering a Compiler. 2004. Keith D. Cooper and
    Linda Torczon. Morgan Kaufmann Publisher
    (available in TextBook rental)
  • Web site http//www.cs.rice.edu/keith/Errata.htm
    l

7
Course detail - Evaluation
GRADABLE POINTS
3 projects 650
Final Exam 150
Presentation 100
In class exercises 100
Total 1000
8
Projects
  • 3 projects scanner, parser and semantic checker,
    code generator. Preferred language to develop
    them is Java, but C/C are welcomed too.
  • Project 3 depends on Project 2, Project 2 depends
    on Project 1.
  • ABSOLUTELY no LATE submission for Project 3
    because of the time consuming to grade this
    project.

9
In class exercises
  • Simple multiple choice questions and simple
    problems will be given in class weekly and
    graded.
  • This requires students to read the assigned
    reading (partly also because this is a discussion
    course instead of lecture)
  • Not all material will be covered in class
  • Book complements the lectures

10
Presentation
  • Each student will do research on a specific
    programming language of his choice. Please let
    the instructor know ahead of time which language
    do you choose
  • Then present 15-20 minutes his research in front
    of class using powerpoint presentation. This will
    be followed by 10 minute questions.

11
Grade
12
Prerequisite
  • Prerequisite COMPSCI 271, and Data Structures
  • Students are responsible for meeting these
    requirements.

13
Compilers
  • What is a compiler?
  • A program that translates an executable program
    in one language into an executable program in
    another language
  • The compiler should improve the program, in some
    way
  • What is an interpreter?

14
Compilers
  • What is a compiler?
  • A program that translates an executable program
    in one language into an executable program in
    another language
  • The compiler should improve the program, in some
    way
  • What is an interpreter?
  • A program that reads an executable program and
    produces the results of executing that program

15
Examples
  • C is typically compiled, Basic is typically
    interpreted
  • Java is compiled to bytecodes (code for the Java
    VM).
  • which are then interpreted
  • Or a hybrid strategy is used
  • Just-in-time compilation

16
Taking a Broader View
  • Compiler Technology Off-Line Processing
  • Goals improved performance and language
    usability
  • Making it practical to use the full power of the
    language
  • Trade-off preprocessing time versus execution
    time (or space)
  • Rule performance of both compiler and
    application must be acceptable to the end user

17
Why study Compilation
  • So even though I'd never actually want to
    write a compiler myself, knowing about compiler
    concepts would have made me a better programmer.
    It's one of those gaps that I regret, which is
    why I think I may actually try to struggle
    through a few chapters from this Engineering a
    Compiler book during the holidays, in between all
    the holiday activities like eating. And shopping.
    And listening to "Santa Got Run Over By a
    Reindeer" for the billionth time

18
Why Study Compilation?
  • Compilers are important system software
    components
  • They are intimately interconnected with
    architecture, systems, programming methodology,
    and language design
  • Compilers include many applications of theory to
    practice
  • Scanning, parsing, static analysis, instruction
    selection
  • Many practical applications have embedded
    languages
  • Commands, macros, formatting tags

19
Why Study Compilation?
  • Many applications have input formats that look
    like languages,
  • Matlab, Mathematica
  • Writing a compiler exposes practical algorithmic
    engineering issues
  • Approximating hard problems efficiency
    scalability

20
Intrinsic interest
  • Compiler construction involves ideas from many
    different parts of computer science

21
Intrinsic merit
  • Compiler construction poses challenging and
    interesting problems
  • Compilers must do a lot but also run fast
  • Compilers have primary responsibility for
    run-time performance
  • Compilers are responsible for making it
    acceptable to use the full power of the
    programming language
  • Computer architects perpetually create new
    challenges for the compiler by building more
    complex machines
  • Compilers must hide that complexity from the
    programmer
  • Success requires mastery of complex interactions

22
Preparation for next class
  • Review the materials for this class
  • Read chapter 1 of the book

23
Overview of compilers
24
High-level View of a Compiler
25
High-level overview of a compiler
  • Implications
  • Must recognize legal (and illegal) programs
  • Must generate correct code
  • Must manage storage of all variables (and code)
  • Must agree with OS linker on format for object
    code
  • Big step up from assembly languageuse higher
    level notations

26
Traditional Two-pass Compiler
  • Use an intermediate representation (IR)
  • Front end maps legal source code into IR
  • Back end maps IR into target machine code
  • Admits multiple front ends multiple passes

27
The Front End
  • Responsibilities
  • Recognize legal ( illegal) programs
  • Report errors in a useful way
  • Produce IR preliminary storage map
  • Shape the code for the back end
  • Much of front end construction can be automated

28
Scanner
  • Maps character stream into words
  • Produces pairs (token) ltits part of speech, a
    wordgt
  • x x y becomes ltid,xgt ltid,xgt ltid,ygt
  • word ? lexeme, part of speech ? token type
  • Typical tokens include number, identifier, , ,
    new, while, if
  • Scanner eliminates white space and comments
  • Speed is important

29
Parser
  • Recognizes context-free syntax reports errors
  • Guides context-sensitive (semantic) analysis
    (type checking)
  • Builds IR for source program
  • Hand-coded parsers are fairly easy to build
  • Most books advocate using automatic parser
    generators

30
Parser
  • Context-free syntax is specified with a grammar
  • SheepNoise ? SheepNoise baa baa
  • SheepNoise -gt nil
  • This grammar defines the set of noises that a
    sheep makes under normal circumstances
  • It is written in a variant of BackusNaur Form
    (BNF)

31
Parser
  • Formally, a grammar G (S,N,T,P)
  • S is the start symbol
  • N is a set of non-terminal symbols
  • T is a set of terminal symbols or words
  • P is a set of productions or rewrite rules
    (P N ? N ?T )

32
Parser
1. goal ? expr 2. expr ? expr op term 3.
term 4. term ? number 5.
id 6. op ? 7.
-
S goal T number, id, , - N goal,
expr, term, op P 1, 2, 3, 4, 5, 6, 7
33
Parser
  • Context-free syntax can be put to better use
  • This grammar defines simple expressions with
    addition subtraction over number and id.
  • This grammar, like many, falls in a class called
    context-free grammars, abbreviated CFG.

34
Parser
Production Result goal 1 expr 2
expr op term 5 expr op y 7 expr -
y 2 expr op term - y 4 expr op 2 -
y 6 expr 2 - y 3 term 2 -
y 5 x 2 - y
x 2 - y
35
Parser
  • A parse can be represented by a tree (parse tree
    or syntax tree)
  • x 2 - y

ltid,ygt
-
1. goal ? expr 2. expr ? expr op term 3.
term 4. term ? number 5.
id 6. op ? 7. -
ltnumber,2gt

ltid,xgt
36
Parser
  • Compilers often use an abstract syntax tree

The AST summarizes grammatical structure, without
including detail about the derivation
37
The Back End
  • Responsibilities
  • Translate IR into target machine code
  • Choose instructions to implement each IR
    operation
  • Decide which value to keep in registers
  • Ensure conformance with system interfaces
  • Automation has been less successful in the back
    end

38
The Back End
  • Instruction Selection
  • Produce fast, compact code
  • Take advantage of target features such as
    addressing modes
  • Usually viewed as a pattern matching problem
  • ad hoc methods, pattern matching, dynamic
    programming

39
The Back End
  • Register Allocation
  • Have each value in a register when it is used
  • Manage a limited set of resources
  • Can change instruction choices insert LOADs
    STOREs
  • Optimal allocation is NP-Complete
    (1 or k registers)
  • Compilers approximate solutions to NP-Complete
    problems

40
The Back End
  • Instruction Scheduling
  • Avoid hardware stalls and interlocks
  • Use all functional units productively
  • Can increase lifetime of variables
    (changing the allocation)
  • Optimal scheduling is NP-Complete in nearly all
    cases
  • Heuristic techniques are well developed

41
Traditional Three-pass Compiler
  • Code Improvement (or Optimization)
  • Analyzes IR and rewrites (or transforms) IR
  • Primary goal is to reduce running time of the
    compiled code
  • May also improve space, power consumption,
  • Must preserve meaning of the code
  • Measured by values of named variables

42
The Optimizer (or Middle End)
  • Typical Transformations
  • Discover propagate some constant value
  • Move a computation to a less frequently executed
    place
  • Specialize some computation based on context
  • Discover a redundant computation remove it
  • Remove useless or unreachable code
  • Encode an idiom in some particularly efficient
    form

Modern optimizers are structured as a series of
passes
43
Modern Restructuring Compiler
HL AST
HL AST
Opt Back End
Machine code
IR
IR Gen
Front End
Source Code
Restructurer
  • Typical Restructuring Transformations
  • Blocking for memory hierarchy and register reuse
  • Vectorization
  • Parallelization
  • All based on dependence
  • Also full and partial inlining

Errors
44
Discussion
  • Consider a simple web browser that takes as
    input a textual string in HTML format and
    displays the specified graphics on the screen. Is
    the display process of compilation or
    interpretation? Why?

45
Next class
  • Lexical analysis
  • Chapter 2
Write a Comment
User Comments (0)
About PowerShow.com