Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Test I Solutions

Size: px
Start display at page:

Download "Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Test I Solutions"

Transcription

1 Department of Eletrial Engineering and Computer iene MAACHUETT INTITUTE OF TECHNOLOGY Fall 2016 Test I olutions 1

2 I Regular Expressions and Finite-tate Automata For Questions 1, 2, and 3, let the alphabet Σ = {a, b}. Let language L be the language of all strings over Σ that ontains the substring aa or bb. 1. [5 points]: Write a regular expression that reognizes language L. olution: (a b) (aa bb)(a b) 2. [5 points]: Draw a state diagram of a nondeterministi finite-state automaton (NFA) that reognizes language L. Remember to indiate starting and aepting states. olution: ee Problem 3. All DFA are NFA. Alternative solution: a,b a q 1 a,b a start q 0 b b q 3 q 2 3. [10 points]: Draw a state diagram of a deterministi finite-state automaton (DFA) that reognizes language L. Note that you an either build a DFA diretly from the English desription or onvert your NFA into a DFA. Remember to indiate starting and aepting states. olution: a q 1 a,b a start q 0 a b b b q 3 q 2 2

3 II Ambiguous Grammar For eah of the following grammars, state if it is ambiguous. If the grammar is ambiguous, find a sentene in the language with two (or more) parse trees, and show the two parse trees. Every lowerase letter indiates a terminal, and every upperase letter indiates a non-terminal. Parsing starts at. 4. [5 points]: d olution: Ambiguous. Example: d d d 5. [5 points]: F + F F F ( ) olution: Not ambiguous. 3

4 6. [5 points]: + F F F ( ) olution: Ambiguous. Example: F F + F F F F 7. [5 points]:? : olution: Not Ambiguous. 4

5 III Left Reursion Consider the following grammar: T $ T T A T ɛ A v = The following is an implementation (in a C-like language) of a reursive desent parser. Note that a parse funtion returns true if it suessfully parses a rule given the input stream, false otherwise. Assume all input ends with exatly one dollar sign $. 1 bool parse() { 2 if (parset()) { 3 if (isdollarign()) { 4 return true; 5 } 6 } 7 return false; 8 } 9 10 bool parset() { 11 if (isv(token)) { 12 if (parset()) { 13 if (parsea()) { 14 return true; 15 } 16 } 17 return false; 18 } else { 19 return true; 20 } 21 } bool parsea() { 24 if (isv(token)) { 25 token = nexttoken(); 26 if (isequal(token)) { 27 token = nexttoken(); 28 if (isc(token)) { 29 token = nexttoken(); 30 return true; 31 } 32 } 33 } 34 return false; 35 } 5

6 8. [6 points]: The reursive desent parser enters infinite reursion beause is left reursive. Redesign the grammar of this language to eliminate left reursion. olution: T $ T A T T ɛ A v = 9. [14 points]: Write the new ode for the reursive desent parser for the new grammar. olution: Both parse() and parsea() are unhanged. bool parset() { if (isv(token)) { if (parsea()) { if (parset()) { return true; } } return false; } else { return true; } } 6

7 IV Control Flow and hort-ciruiting Consider a programming language that inludes a ontrol flow onstrut alled the repeat-until loop. A repeat-until loop is written as follows: repeat { // body statements } until (ondition) The repeat-until loop runs the ode in the loop body, and then heks the ondition. If the ondition evaluates to true, the loop ends; otherwise, the loop repeats. Note that even if the ondition is always true, the loop body will still run one. 10. [10 points]: The semantis of the programming language says that a ompiled program should exeute only as muh as required to determine the value of a boolean ondition. The program evaluates a ompound ondition from left to right. Complete the flowhart on the next page that illustrates the ontrol flow for evaluating the following statements, inluding short-iruit logi for onditionals, assuming the ompiler is not performing any optimizations: int i = 0; int j = 12; repeat { i += j; j = j * 2; } until (i == 36 (i >= 0 && j > 10)) (Hint: after this ode runs, your final values should be i = 12 and j = 24.) 7

8 olution: i = 0; j = 12; i += j; j = j * 2; i == 36 false i >= 0 false true true j > 10 false true end 8

9 11. [10 points]: In the leture, we disussed the implementation of proedures alled shortiruit and destrut. The proedure shortiruit(, t, f) generates the short-iruit ontrol-flow representation for a onditional. This proedure makes the ontrol flow to node t if is true and flow to node f if is false. The proedure returns the begin node for evaluating ondition. The proedure destrut(n) generates the ontrol-flow representation for strutured ode represented by n. This proedure reates a ontrol flow graph for n and returns the begin and end nodes of the graph. Reall that the pseudoode of destrut(n) for an if-else statement is as follows: If n is of the form if () { x1 } else { x2 } then e = new nop; (b1, e1) = destrut(x1); (b2, e2) = destrut(x2); b = shortiruit(, b1, b2); next(e1) = e; next(e2) = e; return (b, e); Implement the pseudoode of destrut(n) for a repeat-until loop: If n is of the form repeat { x } until () then olution: e = new nop; (b, e1) = destrut(x); b = shortiruit(, e, b); next(e1) = b; return (b, e); 9

10 V Code Generation for Proedures Consider the following funtion in C and its orresponding assembly ode generated by a ompliler. Note that long is a 64-bit integer. long bar(long x) { return x+x; } 1 pushq %rbp // push the value of %rbp to the stak 2 movq %rsp, %rbp // opy the value of %rsp to %rbp 3 movq %rdi, -8(%rbp) // opy the value of %rdi to the stak 4 movq -8(%rbp), %rdi // opy the value on the stak to %rdi 5 addq -8(%rbp), %rdi // add the value on the stak to %rdi 6 movq %rdi, %rax // opy the value of %rdi to %rax 7 popq %rbp // pop the top value from the stak to %rbp 8 ret // return from the funtion The ompiler follows the standard Linux x86-64 alling onvention: A aller proedure/funtion passes the first 6 arguments, from left to right, in %rdi, %rsi, %rdx, %rx, %r8, %r9. Any remaining arguments are passed on the stak, from right to left. The aller owns registers %rsp, %rbp, %rbx, and %r12-%r15. The allee proedure/funtion is responsible for ensuring that these registers have the same value after the all as before the all. Note that %rsp and %rbp are the stak and base registers. Registers %rsp, %rbp, %rbx, and %r12-%r15 are the allee-save registers. The allee owns the remaining registers %rax, %rx, %rdx, %rsi, %rdi, and %r8-%r11. These registers an have different values after the all as before the all. These registers are the aller-save registers. The allee plaes its return value in %rax. 10

11 Whih of the following possible generated ode sequenes for bar are orret in the sense that 1) they ompute the orret return value for bar and 2) they follow the the standard Linux x86-64 alling onvention? Provide your answer by irling either Corret or Inorret below eah ode sequene. 12. [5 points]: 1 pushq %rbp // push the value of %rbp to the stak 2 movq %rsp, %rbp // opy the value of %rsp to %rbp 3 movq %rdi, -8(%rbp) // opy the value of %rdi to the stak 4 addq %rdi, %rdi // add the value of %rdi to %rdi 5 movq %rdi, %rax // opy the value of %rdi to %rax 6 popq %rbp // pop the top value from the stak to %rbp 7 retq // return from the funtion Corret Inorret olution: Corret 13. [5 points]: 1 movq %rdi, -8(%rsp) // opy the value of %rdi to the stak 2 addq -8(%rsp), %rdi // add the value on the stak to %rdi 3 movq %rdi, %rax // opy the value of %rdi to %rax 4 retq // return from the funtion Corret Inorret olution: Corret 11

12 The ode in the next two questions is also ompiled by a ompiler that adheres to the Linux x86-64 alling onvention, whih is repeated below for your onveniene. A aller proedure/funtion passes the first 6 arguments, from left to right, in %rdi, %rsi, %rdx, %rx, %r8, %r9. Any remaining arguments are passed on the stak, from right to left. The aller owns registers %rsp, %rbp, %rbx, and %r12-%r15. The allee proedure/funtion is responsible for ensuring that these registers have the same value after the all as before the all. Note that %rsp and %rbp are the stak and base registers. Registers %rsp, %rbp, %rbx, and %r12-%r15 are the allee-save registers. The allee owns the remaining registers %rax, %rx, %rdx, %rsi, %rdi, and %r8-%r11. These registers an have different values after the all as before the all. These registers are the aller-save registers. The allee plaes its return value in %rax. The ompiler will try to alloate variables in registers to minimize movement between memory and registers. In other words, it will deide that the value of a speifi variable should be stored in a speifi register, then aess that value from that register diretly. The goal is to ensure that as many values are aessed from registers as possible and to minimize any need to save and restore registers to and from memory. 12

13 14. [6 points]: Into what registers should the ompiler alloate n, i, x, when it ompiles the proedure g() below? If there are multiple equivalent register assignments, you only need to write one. Assume that funtions g() and f() are ompiled separately. 1 long g() { 2 long n = 100; 3 long i = 0; 4 long x = 0; 5 while (i < n) { 6 x = x + f(i); 7 i = i + 1; 8 } 9 return x; 10 } Alloate n in register: olution: %r12 Alloate i in register: olution: %r13 Alloate x in register: olution: %r14 Note: Any 3 different registers from the following list are OK: %rbx, %r12, %r13, %r14, and %r15. 13

14 15. [4 points]: Into what registers should the ompiler alloate j and y, when it ompiles the proedure f() below? 1 long f(long j) { 2 long y = j * j; 3 y = j + 10; 4 return y; 5 } Alloate j in register: olution: %rdi Alloate y in register: olution: %rax Note: Any 2 different aller saved registers are OK. 14

Test I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science

Test I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science Department of Electrical Engineering and Computer cience MAACHUETT INTITUTE OF TECHNOLOGY 6.035 Fall 2017 Test I olutions Mean 83.63 Median 86 td. dev 12.03 1 I Regular Expressions and Finite-tate Automata

More information

Total 100

Total 100 CS331 SOLUTION Problem # Points 1 10 2 15 3 25 4 20 5 15 6 15 Total 100 1. ssume you are dealing with a ompiler for a Java-like language. For eah of the following errors, irle whih phase would normally

More information

Assembly Language: Function Calls

Assembly Language: Function Calls Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems x86-64 solutions Pertinent instructions and conventions 2 Function Call Problems (1) Calling and returning

More information

Compilation Lecture 11a. Register Allocation Noam Rinetzky. Text book: Modern compiler implementation in C Andrew A.

Compilation Lecture 11a. Register Allocation Noam Rinetzky. Text book: Modern compiler implementation in C Andrew A. Compilation 0368-3133 Leture 11a Text book: Modern ompiler implementation in C Andrew A. Appel Register Alloation Noam Rinetzky 1 Registers Dediated memory loations that an be aessed quikly, an have omputations

More information

COMP 181. Prelude. Intermediate representations. Today. Types of IRs. High-level IR. Intermediate representations and code generation

COMP 181. Prelude. Intermediate representations. Today. Types of IRs. High-level IR. Intermediate representations and code generation Prelude COMP 181 Intermediate representations and ode generation November, 009 What is this devie? Large Hadron Collider What is a hadron? Subatomi partile made up of quarks bound by the strong fore What

More information

CSE P 501 Exam Sample Solution 12/1/11

CSE P 501 Exam Sample Solution 12/1/11 Question 1. (10 points, 5 each) Regular expressions. Give regular expressions that generate the following sets of strings. You may only use the basic operations of concatenation, choice ( ), and repetition

More information

Machine Program: Procedure. Zhaoguo Wang

Machine Program: Procedure. Zhaoguo Wang Machine Program: Procedure Zhaoguo Wang Requirements of procedure calls? P() { y = Q(x); y++; 1. Passing control int Q(int i) { int t, z; return z; Requirements of procedure calls? P() { y = Q(x); y++;

More information

Princeton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Function Calls

Princeton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Function Calls Princeton University Computer Science 217: Introduction to Programming Systems Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems x86-64 solutions Pertinent

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 28, 2018 at 06:32 CS429 Slideset 9: 1 Mechanisms in Procedures

More information

XML Data Streams. XML Stream Processing. XML Stream Processing. Yanlei Diao. University of Massachusetts Amherst

XML Data Streams. XML Stream Processing. XML Stream Processing. Yanlei Diao. University of Massachusetts Amherst XML Stream Proessing Yanlei Diao University of Massahusetts Amherst XML Data Streams XML is the wire format for data exhanged online. Purhase orders http://www.oasis-open.org/ommittees/t_home.php?wg_abbrev=ubl

More information

Machine-level Programs Procedure

Machine-level Programs Procedure Computer Systems Machine-level Programs Procedure Han, Hwansoo Mechanisms in Procedures Passing control To beginning of procedure code Back to return point Passing data Procedure arguments Return value

More information

Machine-Level Programming III: Procedures

Machine-Level Programming III: Procedures Machine-Level Programming III: Procedures CSE 238/2038/2138: Systems Programming Instructor: Fatma CORUT ERGİN Slides adapted from Bryant & O Hallaron s slides Mechanisms in Procedures Passing control

More information

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon Carnegie Mellon Machine-Level Programming III: Procedures 15-213/18-213/14-513/15-513: Introduction to Computer Systems 7 th Lecture, September 18, 2018 Today Procedures Mechanisms Stack Structure Calling

More information

Gray Codes for Reflectable Languages

Gray Codes for Reflectable Languages Gray Codes for Refletable Languages Yue Li Joe Sawada Marh 8, 2008 Abstrat We lassify a type of language alled a refletable language. We then develop a generi algorithm that an be used to list all strings

More information

Recursion examples: Problem 2. (More) Recursion and Lists. Tail recursion. Recursion examples: Problem 2. Recursion examples: Problem 3

Recursion examples: Problem 2. (More) Recursion and Lists. Tail recursion. Recursion examples: Problem 2. Recursion examples: Problem 3 Reursion eamples: Problem 2 (More) Reursion and s Reursive funtion to reverse a string publi String revstring(string str) { if(str.equals( )) return str; return revstring(str.substring(1, str.length()))

More information

Machine-Level Programming (2)

Machine-Level Programming (2) Machine-Level Programming (2) Yanqiao ZHU Introduction to Computer Systems Project Future (Fall 2017) Google Camp, Tongji University Outline Control Condition Codes Conditional Branches and Conditional

More information

Department of Electrical and Computer Engineering University of Wisconsin Madison. Fall

Department of Electrical and Computer Engineering University of Wisconsin Madison. Fall Department of Eletrial and Computer Engineering University of Wisonsin Madison ECE 553: Testing and Testable Design of Digital Systems Fall 2014-2015 Assignment #2 Date Tuesday, September 25, 2014 Due

More information

Function Calls and Stack

Function Calls and Stack Function Calls and Stack Philipp Koehn 16 April 2018 1 functions Another Example 2 C code with an undefined function int main(void) { int a = 2; int b = do_something(a); urn b; } This can be successfully

More information

CSE 351 Midterm - Winter 2015

CSE 351 Midterm - Winter 2015 CSE 351 Midterm - Winter 2015 February 09, 2015 Please read through the entire examination first! We designed this exam so that it can be completed in 50 minutes and, hopefully, this estimate will prove

More information

1 Number Representation(10 points)

1 Number Representation(10 points) Name: Sp15 Midterm Q1 1 Number Representation(10 points) 1 NUMBER REPRESENTATION(10 POINTS) Let x=0xe and y=0x7 be integers stored on a machine with a word size of 4bits. Show your work with the following

More information

Procedures and the Call Stack

Procedures and the Call Stack Procedures and the Call Stack Topics Procedures Call stack Procedure/stack instructions Calling conventions Register-saving conventions Why Procedures? Why functions? Why methods? int contains_char(char*

More information

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA? R1 SET - 1 1. a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA? 2. a) Design a DFA that accepts the language over = {, 1} of all strings that

More information

6.035 Project 3: Unoptimized Code Generation. Jason Ansel MIT - CSAIL

6.035 Project 3: Unoptimized Code Generation. Jason Ansel MIT - CSAIL 6.035 Project 3: Unoptimized Code Generation Jason Ansel MIT - CSAIL Quiz Monday 50 minute quiz Monday Covers everything up to yesterdays lecture Lexical Analysis (REs, DFAs, NFAs) Syntax Analysis (CFGs,

More information

EXAMINATIONS 2014 TRIMESTER 1 SWEN 430. Compiler Engineering. This examination will be marked out of 180 marks.

EXAMINATIONS 2014 TRIMESTER 1 SWEN 430. Compiler Engineering. This examination will be marked out of 180 marks. T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2014 TRIMESTER 1 SWEN 430 Compiler Engineering Time Allowed: THREE HOURS Instructions:

More information

1 The Knuth-Morris-Pratt Algorithm

1 The Knuth-Morris-Pratt Algorithm 5-45/65: Design & Analysis of Algorithms September 26, 26 Leture #9: String Mathing last hanged: September 26, 27 There s an entire field dediated to solving problems on strings. The book Algorithms on

More information

Chapter 2: Introduction to Maple V

Chapter 2: Introduction to Maple V Chapter 2: Introdution to Maple V 2-1 Working with Maple Worksheets Try It! (p. 15) Start a Maple session with an empty worksheet. The name of the worksheet should be Untitled (1). Use one of the standard

More information

CSE351 Spring 2018, Midterm Exam April 27, 2018

CSE351 Spring 2018, Midterm Exam April 27, 2018 CSE351 Spring 2018, Midterm Exam April 27, 2018 Please do not turn the page until 11:30. Last Name: First Name: Student ID Number: Name of person to your left: Name of person to your right: Signature indicating:

More information

CS 3330 Exam 1 Fall 2017 Computing ID:

CS 3330 Exam 1 Fall 2017 Computing ID: S 3330 Fall 2017 xam 1 Variant page 1 of 8 mail I: S 3330 xam 1 Fall 2017 Name: omputing I: Letters go in the boxes unless otherwise specified (e.g., for 8 write not 8 ). Write Letters clearly: if we are

More information

CSE 351 Midterm - Winter 2015 Solutions

CSE 351 Midterm - Winter 2015 Solutions CSE 351 Midterm - Winter 2015 Solutions February 09, 2015 Please read through the entire examination first! We designed this exam so that it can be completed in 50 minutes and, hopefully, this estimate

More information

Lecture 14. Recursion

Lecture 14. Recursion Leture 14 Reursion Announements for Today Prelim 1 Tonight at 5:15 OR 7:30 A D (5:15, Uris G01) E-K (5:15, Statler) L P (7:30, Uris G01) Q-Z (7:30, Statler) Graded y noon on Sun Sores will e in CMS In

More information

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Assembly III: Procedures Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Mechanisms in Procedures Passing control To beginning of procedure code

More information

The Stack & Procedures

The Stack & Procedures The Stack & Procedures CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/648/

More information

void P() {... y = Q(x); print(y); return; } ... int Q(int t) { int v[10];... return v[t]; } Computer Systems: A Programmer s Perspective

void P() {... y = Q(x); print(y); return; } ... int Q(int t) { int v[10];... return v[t]; } Computer Systems: A Programmer s Perspective void P() { y = Q(x); print(y); return;... int Q(int t) { int v[10]; return v[t]; Computer Systems: A Programmer s Perspective %rax %rbx 0x101 0x41 0x7FFFFA8 0x1 0x7FFFFF8 0xB5A9 0x7FFFFF0 0x789ABC 0x7FFFFE8

More information

Computer Organization: A Programmer's Perspective

Computer Organization: A Programmer's Perspective A Programmer's Perspective Instruction Set Architecture Gal A. Kaminka galk@cs.biu.ac.il Outline: CPU Design Background Instruction sets Logic design Sequential Implementation A simple, but not very fast

More information

Multiple Assignments

Multiple Assignments Two Outputs Conneted Together Multiple Assignments Two Outputs Conneted Together if (En1) Q

More information

1. The collection of the vowels in the word probability. 2. The collection of real numbers that satisfy the equation x 9 = 0.

1. The collection of the vowels in the word probability. 2. The collection of real numbers that satisfy the equation x 9 = 0. C HPTER 1 SETS I. DEFINITION OF SET We begin our study of probability with the disussion of the basi onept of set. We assume that there is a ommon understanding of what is meant by the notion of a olletion

More information

Partial Character Decoding for Improved Regular Expression Matching in FPGAs

Partial Character Decoding for Improved Regular Expression Matching in FPGAs Partial Charater Deoding for Improved Regular Expression Mathing in FPGAs Peter Sutton Shool of Information Tehnology and Eletrial Engineering The University of Queensland Brisbane, Queensland, 4072, Australia

More information

CSE 351 Midterm - Winter 2017

CSE 351 Midterm - Winter 2017 CSE 351 Midterm - Winter 2017 February 08, 2017 Please read through the entire examination first, and make sure you write your name and NetID on all pages! We designed this exam so that it can be completed

More information

Machine/Assembler Language Putting It All Together

Machine/Assembler Language Putting It All Together COMP 40: Machine Structure and Assembly Language Programming Fall 2015 Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Email: noah@cs.tufts.edu Web: http://www.cs.tufts.edu/~noah

More information

Mechanisms in Procedures. CS429: Computer Organization and Architecture. x86-64 Stack. x86-64 Stack Pushing

Mechanisms in Procedures. CS429: Computer Organization and Architecture. x86-64 Stack. x86-64 Stack Pushing CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 28, 2018 at 06:32 Mechanisms in Procedures Passing Control

More information

Midterm I (Solutions) CS164, Spring 2002

Midterm I (Solutions) CS164, Spring 2002 Midterm I (Solutions) CS164, Spring 2002 February 28, 2002 Please read all instructions (including these) carefully. There are 9 pages in this exam and 5 questions, each with multiple parts. Some questions

More information

CSC 252: Computer Organization Spring 2018: Lecture 11

CSC 252: Computer Organization Spring 2018: Lecture 11 CSC 252: Computer Organization Spring 2018: Lecture 11 Instructor: Yuhao Zhu Department of Computer Science University of Rochester Action Items: Assignment 3 is due March 2, midnight Announcement Programming

More information

Midterm I - Solution CS164, Spring 2014

Midterm I - Solution CS164, Spring 2014 164sp14 Midterm 1 - Solution Midterm I - Solution CS164, Spring 2014 March 3, 2014 Please read all instructions (including these) carefully. This is a closed-book exam. You are allowed a one-page handwritten

More information

CSE P 501 Exam 12/1/11

CSE P 501 Exam 12/1/11 Name There are 7 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following references:

More information

The Stack & Procedures

The Stack & Procedures The Stack & Procedures CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Homework 2 due

More information

%r8 %r8d. %r9 %r9d. %r10 %r10d. %r11 %r11d. %r12 %r12d. %r13 %r13d. %r14 %r14d %rbp. %r15 %r15d. Sean Barker

%r8 %r8d. %r9 %r9d. %r10 %r10d. %r11 %r11d. %r12 %r12d. %r13 %r13d. %r14 %r14d %rbp. %r15 %r15d. Sean Barker Procedure Call Registers Return %rax %eax %r8 %r8d Arg 5 %rbx %ebx %r9 %r9d Arg 6 Arg 4 %rcx %ecx %r10 %r10d Arg 3 %rdx %edx %r11 %r11d Arg 2 %rsi %esi %r12 %r12d Arg 1 %rdi %edi %r13 %r13d ptr %esp %r14

More information

Compiler Design IIIT Kalyani, West Bengal 1. Introduction. Goutam Biswas. Lect 1

Compiler Design IIIT Kalyani, West Bengal 1. Introduction. Goutam Biswas. Lect 1 Compiler Design IIIT Kalyani, West Bengal 1 Introduction Compiler Design IIIT Kalyani, West Bengal 2 Programming a Computer High level language program Assembly language program Machine language program

More information

Machine- Level Representa2on: Procedure

Machine- Level Representa2on: Procedure Machine- Level Representa2on: Procedure CSCI 2021: Machine Architecture and Organiza2on Pen- Chung Yew Department Computer Science and Engineering University of Minnesota With Slides from Bryant, O Hallaron

More information

BSPLND, A B-Spline N-Dimensional Package for Scattered Data Interpolation

BSPLND, A B-Spline N-Dimensional Package for Scattered Data Interpolation BSPLND, A B-Spline N-Dimensional Pakage for Sattered Data Interpolation Mihael P. Weis Traker Business Systems 85 Terminal Drive, Suite Rihland, WA 995-59-946-544 mike@vidian.net Robert R. Lewis Washington

More information

CMSC 330, Fall 2018 Midterm 2

CMSC 330, Fall 2018 Midterm 2 CMSC 330, Fall 2018 Midterm 2 Name Teaching Assistant Kameron Aaron Danny Chris Michael P. Justin Cameron B. Derek Kyle Hasan Shriraj Cameron M. Alex Michael S. Pei-Jo Instructions Do not start this exam

More information

Do not turn the page until 5:10.

Do not turn the page until 5:10. University of Washington Computer Science & Engineering Autumn 2017 Instructor: Justin Hsia 2017-10-30 Last Name: First Name: Student ID Number: Name of person to your Left Right All work is my own. I

More information

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81%

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81% Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81% 1. (2 pts) See text. You can t be sloppy defining terms like this. You must show a bijection between the natural numbers

More information

Generation. representation to the machine

Generation. representation to the machine Unoptimized i Code Generation From the intermediate representation to the machine code 5 Outline Introduction Machine Language Overview of a modern processor Memory Layout Procedure Abstraction Procedure

More information

Assembly Programming IV

Assembly Programming IV Assembly Programming IV CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis 1 Administrivia Homework 2 due

More information

Areas for growth: I love feedback

Areas for growth: I love feedback Assembly part 2 1 Areas for growth: I love feedback Speed, I will go slower. Clarity. I will take time to explain everything on the slides. Feedback. I give more Kahoot questions and explain each answer.

More information

CMSC 330, Fall 2009, Practice Problem 3 Solutions

CMSC 330, Fall 2009, Practice Problem 3 Solutions CMC 330, Fall 2009, Practice Problem 3 olutions 1. Context Free Grammars a. List the 4 components of a context free grammar. Terminals, non-terminals, productions, start symbol b. Describe the relationship

More information

18-600: Recitation #4 Exploits

18-600: Recitation #4 Exploits 18-600: Recitation #4 Exploits 20th September 2016 Agenda More x86-64 assembly Buffer Overflow Attack Return Oriented Programming Attack 3 Recap: x86-64: Register Conventions Arguments passed in registers:

More information

CS356: Discussion #8 Buffer-Overflow Attacks. Marco Paolieri

CS356: Discussion #8 Buffer-Overflow Attacks. Marco Paolieri CS356: Discussion #8 Buffer-Overflow Attacks Marco Paolieri (paolieri@usc.edu) Previous Example #include void unreachable() { printf("impossible.\n"); void hello() { char buffer[6]; scanf("%s",

More information

1 Disjoint-set data structure.

1 Disjoint-set data structure. CS 124 Setion #4 Union-Fin, Greey Algorithms 2/20/17 1 Disjoint-set ata struture. 1.1 Operations Disjoint-set ata struture enale us to effiiently perform operations suh as plaing elements into sets, querying

More information

Reading Object Code. A Visible/Z Lesson

Reading Object Code. A Visible/Z Lesson Reading Objet Code A Visible/Z Lesson The Idea: When programming in a high-level language, we rarely have to think about the speifi ode that is generated for eah instrution by a ompiler. But as an assembly

More information

Buffer Overflow Attack (AskCypert CLaaS)

Buffer Overflow Attack (AskCypert CLaaS) Buffer Overflow Attack (AskCypert CLaaS) ---------------------- BufferOverflow.c code 1. int main(int arg c, char** argv) 2. { 3. char name[64]; 4. printf( Addr;%p\n, name); 5. strcpy(name, argv[1]); 6.

More information

Credits and Disclaimers

Credits and Disclaimers Credits and Disclaimers 1 The examples and discussion in the following slides have been adapted from a variety of sources, including: Chapter 3 of Computer Systems 3 nd Edition by Bryant and O'Hallaron

More information

CS 261 Fall Machine and Assembly Code. Data Movement and Arithmetic. Mike Lam, Professor

CS 261 Fall Machine and Assembly Code. Data Movement and Arithmetic. Mike Lam, Professor CS 261 Fall 2018 0000000100000f50 55 48 89 e5 48 83 ec 10 48 8d 3d 3b 00 00 00 c7 0000000100000f60 45 fc 00 00 00 00 b0 00 e8 0d 00 00 00 31 c9 89 0000000100000f70 45 f8 89 c8 48 83 c4 10 5d c3 Mike Lam,

More information

Lexical Analysis. Chapter 2

Lexical Analysis. Chapter 2 Lexical Analysis Chapter 2 1 Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexers Regular expressions Examples

More information

1. A student is testing an implementation of a C function; when compiled with gcc, the following x86-64 assembly code is produced:

1. A student is testing an implementation of a C function; when compiled with gcc, the following x86-64 assembly code is produced: This assignment refers to concepts discussed in sections 2.1.1 2.1.3, 2.1.8, 2.2.1 2.2.6, 3.2, 3.4, and 3.7.1of csapp; see that material for discussions of x86 assembly language and its relationship to

More information

Do not turn the page until 5:10.

Do not turn the page until 5:10. University of Washington Computer Science & Engineering Autumn 2017 Instructor: Justin Hsia 2017-10-30 Last Name: First Name: Perfect Perry Student ID Number: 1234567 Name of person to your Left Right

More information

2068 (I) Attempt all questions.

2068 (I) Attempt all questions. 2068 (I) 1. What do you mean by compiler? How source program analyzed? Explain in brief. 2. Discuss the role of symbol table in compiler design. 3. Convert the regular expression 0 + (1 + 0)* 00 first

More information

Unoptimized Code Generation

Unoptimized Code Generation Unoptimized Code Generation Last time we left off on the procedure abstraction Saman Amarasinghe 2 6.035 MIT Fall 1998 The Stack Arguments 0 to 6 are in: %b %rbp %rsp %rdi, %rsi, %rdx, %rcx, %r8 and %r9

More information

Machine Language CS 3330 Samira Khan

Machine Language CS 3330 Samira Khan Machine Language CS 3330 Samira Khan University of Virginia Feb 2, 2017 AGENDA Logistics Review of Abstractions Machine Language 2 Logistics Feedback Not clear Hard to hear Use microphone Good feedback

More information

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string. CS 340, Fll 2016 Sep 29th Exm 1 Nme: Note: in ll questions, the speil symol ɛ (epsilon) is used to indite the empty string. Question 1. [10 points] Speify regulr expression tht genertes the lnguge over

More information

WARNING for Autumn 2004:

WARNING for Autumn 2004: CSE 413 Programming Languages Autumn 2003 Max Points 50 Closed book, closed notes, no electronics. Do your own work! WARNING for Autumn 2004 Last year s exam did not cover Scheme and Java, but this year

More information

C++ Named Return Value Optimization

C++ Named Return Value Optimization C++ Named Return Value Optimization post. Robert.Schneider@hotmail.de meetup.com/c-user-group-karlsruhe auto create() -> T { T castor /* initialize */; //... return castor; } void use() { T pollux = create();

More information

Definitions Homework. Quine McCluskey Optimal solutions are possible for some large functions Espresso heuristic. Definitions Homework

Definitions Homework. Quine McCluskey Optimal solutions are possible for some large functions Espresso heuristic. Definitions Homework EECS 33 There be Dragons here http://ziyang.ees.northwestern.edu/ees33/ Teaher: Offie: Email: Phone: L477 Teh dikrp@northwestern.edu 847 467 2298 Today s material might at first appear diffiult Perhaps

More information

Computer Systems C S Cynthia Lee

Computer Systems C S Cynthia Lee Computer Systems C S 1 0 7 Cynthia Lee 2 Today s Topics Function call and return in x86-64 Registers Call stack NEXT TIME: NEW topic: the build process Taking a look at each step of the process Preprocessor,

More information

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Theory of Computation Dr. Weiss Extra Practice Exam Solutions Name: of 7 Theory of Computation Dr. Weiss Extra Practice Exam Solutions Directions: Answer the questions as well as you can. Partial credit will be given, so show your work where appropriate. Try to be

More information

Compiling C Programs Into X86-64 Assembly Programs

Compiling C Programs Into X86-64 Assembly Programs CSE 2421: Systems I Low-Level Programming and Computer Organization Compiling C Programs Into X86-64 Assembly Programs Part B: If Else, Loops, Recursion & Switch Presentation L Read/Study: Bryant 3.6 Gojko

More information

Do not turn the page until 5:10.

Do not turn the page until 5:10. University of Washington Computer Science & Engineering Autumn 2018 Instructor: Justin Hsia 2018-10-29 Last Name: First Name: Student ID Number: Name of person to your Left Right All work is my own. I

More information

A DYNAMIC ACCESS CONTROL WITH BINARY KEY-PAIR

A DYNAMIC ACCESS CONTROL WITH BINARY KEY-PAIR Malaysian Journal of Computer Siene, Vol 10 No 1, June 1997, pp 36-41 A DYNAMIC ACCESS CONTROL WITH BINARY KEY-PAIR Md Rafiqul Islam, Harihodin Selamat and Mohd Noor Md Sap Faulty of Computer Siene and

More information

Reading Object Code. A Visible/Z Lesson

Reading Object Code. A Visible/Z Lesson Reading Objet Code A Visible/Z Lesson The Idea: When programming in a high-level language, we rarely have to think about the speifi ode that is generated for eah instrution by a ompiler. But as an assembly

More information

Stack Frame Components. Using the Stack (4) Stack Structure. Updated Stack Structure. Caller Frame Arguments 7+ Return Addr Old %rbp

Stack Frame Components. Using the Stack (4) Stack Structure. Updated Stack Structure. Caller Frame Arguments 7+ Return Addr Old %rbp Stack Frame Components Frame pointer %rbp Stack pointer Caller Frame rguments 7+ Return ddr Old %rbp Saved Registers + Local Variables rgument Build 1 Using the Stack (4) Stack Structure long call_incr()

More information

Compiler Construction

Compiler Construction Compiler Construction Exercises 1 Review of some Topics in Formal Languages 1. (a) Prove that two words x, y commute (i.e., satisfy xy = yx) if and only if there exists a word w such that x = w m, y =

More information

CS164: Midterm I. Fall 2003

CS164: Midterm I. Fall 2003 CS164: Midterm I Fall 2003 Please read all instructions (including these) carefully. Write your name, login, and circle the time of your section. Read each question carefully and think about what s being

More information

University of Washington

University of Washington Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: Computer system: get_mpg: pushq %rbp movq %rsp, %rbp... popq %rbp

More information

The Compilation Process

The Compilation Process Crash Course in C Lecture 2 Moving from Python to C: The compilation process Differences between Python and C Variable declaration and strong typing The memory model: data vs. address The Compilation Process

More information

6.1. CS356 Unit 6. x86 Procedures Basic Stack Frames

6.1. CS356 Unit 6. x86 Procedures Basic Stack Frames 6.1 CS356 Unit 6 x86 Procedures Basic Stack Frames 6.2 Review of Program Counter (Instruc. Pointer) PC/IP is used to fetch an instruction PC/IP contains the address of the next instruction The value in

More information

C to Assembly SPEED LIMIT LECTURE Performance Engineering of Software Systems. I-Ting Angelina Lee. September 13, 2012

C to Assembly SPEED LIMIT LECTURE Performance Engineering of Software Systems. I-Ting Angelina Lee. September 13, 2012 6.172 Performance Engineering of Software Systems SPEED LIMIT PER ORDER OF 6.172 LECTURE 3 C to Assembly I-Ting Angelina Lee September 13, 2012 2012 Charles E. Leiserson and I-Ting Angelina Lee 1 Bugs

More information

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 261: MIDTERM 1 February 14, 2017

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 261: MIDTERM 1 February 14, 2017 THE UNIVERSITY OF BRITISH COLUMBIA CPSC 261: MIDTERM 1 February 14, 2017 Last Name: First Name: Signature: UBC Student #: Important notes about this examination 1. You have 70 minutes to write the 6 questions

More information

Outline. 1 Scanning Tokens. 2 Regular Expresssions. 3 Finite State Automata

Outline. 1 Scanning Tokens. 2 Regular Expresssions. 3 Finite State Automata Outline 1 2 Regular Expresssions Lexical Analysis 3 Finite State Automata 4 Non-deterministic (NFA) Versus Deterministic Finite State Automata (DFA) 5 Regular Expresssions to NFA 6 NFA to DFA 7 8 JavaCC:

More information

CMSC 330, Fall 2018 Midterm 2

CMSC 330, Fall 2018 Midterm 2 CMSC 330, Fall 2018 Midterm 2 Name Teaching Assistant Kameron Aaron Danny Chris Michael P. Justin Cameron B. Derek Kyle Hasan Shriraj Cameron M. Alex Michael S. Pei-Jo Instructions Do not start this exam

More information

Introduction. Compiler Design CSE Overview. 2 Syntax-Directed Translation. 3 Phases of Translation

Introduction. Compiler Design CSE Overview. 2 Syntax-Directed Translation. 3 Phases of Translation Introduction Compiler Design CSE 504 1 Overview 2 Syntax-Directed Translation 3 Phases of Translation Last modifled: Mon Jan 25 2016 at 00:15:02 EST Version: 1.5 23:45:54 2013/01/28 Compiled at 12:59 on

More information

Algorithms, Mechanisms and Procedures for the Computer-aided Project Generation System

Algorithms, Mechanisms and Procedures for the Computer-aided Project Generation System Algorithms, Mehanisms and Proedures for the Computer-aided Projet Generation System Anton O. Butko 1*, Aleksandr P. Briukhovetskii 2, Dmitry E. Grigoriev 2# and Konstantin S. Kalashnikov 3 1 Department

More information

CIS 341 Midterm March 2, Name (printed): Pennkey (login id): Do not begin the exam until you are told to do so.

CIS 341 Midterm March 2, Name (printed): Pennkey (login id): Do not begin the exam until you are told to do so. CIS 341 Midterm March 2, 2017 Name (printed): Pennkey (login id): My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in completing this examination.

More information

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11 X86 Debug Computer Systems Section 3.11 GDB is a Source Level debugger We have learned how to debug at the C level But the machine is executing X86 object code! How does GDB play the shell game? Makes

More information

UCSB Math TI-85 Tutorials: Basics

UCSB Math TI-85 Tutorials: Basics 3 UCSB Math TI-85 Tutorials: Basis If your alulator sreen doesn t show anything, try adjusting the ontrast aording to the instrutions on page 3, or page I-3, of the alulator manual You should read the

More information

Space- and Time-Efficient BDD Construction via Working Set Control

Space- and Time-Efficient BDD Construction via Working Set Control Spae- and Time-Effiient BDD Constrution via Working Set Control Bwolen Yang Yirng-An Chen Randal E. Bryant David R. O Hallaron Computer Siene Department Carnegie Mellon University Pittsburgh, PA 15213.

More information

CS 3330 Exam 2 Spring 2017 Name: EXAM KEY Computing ID: KEY

CS 3330 Exam 2 Spring 2017 Name: EXAM KEY Computing ID: KEY S 3330 Spring 2017 Exam 2 Variant E page 1 of 6 Email I: KEY S 3330 Exam 2 Spring 2017 Name: EXM KEY omputing I: KEY Letters go in the boxes unless otherwise specified (e.g., for 8 write not 8 ). Write

More information

CSE 351 Midterm Exam

CSE 351 Midterm Exam University of Washington Computer Science & Engineering Winter 2018 Instructor: Mark Wyse February 5, 2018 CSE 351 Midterm Exam Last Name: First Name: SOLUTIONS UW Student ID Number: UW NetID (username):

More information

Run Time Environment. Implementing Object-Oriented Languages

Run Time Environment. Implementing Object-Oriented Languages Run Time Environment Implementing Objet-Oriented Languages Copright 2017, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers lass at the Universit of Southern California have epliit

More information

Computer Architecture I: Outline and Instruction Set Architecture. CENG331 - Computer Organization. Murat Manguoglu

Computer Architecture I: Outline and Instruction Set Architecture. CENG331 - Computer Organization. Murat Manguoglu Computer Architecture I: Outline and Instruction Set Architecture CENG331 - Computer Organization Murat Manguoglu Adapted from slides of the textbook: http://csapp.cs.cmu.edu/ Outline Background Instruction

More information

Intel x86-64 and Y86-64 Instruction Set Architecture

Intel x86-64 and Y86-64 Instruction Set Architecture CSE 2421: Systems I Low-Level Programming and Computer Organization Intel x86-64 and Y86-64 Instruction Set Architecture Presentation J Read/Study: Bryant 3.1 3.5, 4.1 Gojko Babić 03-07-2018 Intel x86

More information