Introduction to Compilers Professor Jeremy Siek
|
|
- Martha Violet Chapman
- 6 years ago
- Views:
Transcription
1 Professor Jeremy Siek This exam has 12 questions, for a total of 100 points points Draw a parse tree and an abstract syntax tree for the following program given the grammar below. In the case of ambiguities, use the precedences of the Python language. The abstract syntax tree should match what the Python compiler module would produce. Grammar: ::= integer identifier "(" L ")" "lambda" IL ":" "(" ")" L ::= "," L IL ::= identifier identifier "," IL Program: (lambda x, y: x)(lambda z: z, 2)(42) Parse tree: L L IL L IL IL ( lambda x, y : x ) ( lambda z : z, 2 ) ( 42 ) Abstract syntax tree: CallFunc node args CallFunc Const(42) node args args Lambda[x,y] code Name(x) Lambda[z] code Name(z) Const(2)
2 2. 5 points Translate the following P 1 program to GNU C. You can use the C functions declared in the Appendix. print input() and (input() + 5 or input()) int main() { print_any(({ pyobj tmp2 = input(); pyobj_to_bool(tmp2)? ({ pyobj tmp1 = ({ pyobj left0 = input(); add(left0, int_to_pyobj(5)); ); pyobj_to_bool(tmp1)? tmp1 : input(); ) : tmp2; )); return 0; Page 2 of 11
3 3. 10 points Perform type analysis and type specialization on the following program and translate it to GNU C. You may use the C functions declared in the Appendix. x = 0 n = 10 i = 0 if input() else 1 while i < n: if i == 0: y = x x = x * 0.5 i = i + 1 print y int main() { pyobj y; int i; int n; pyobj x; x = int_to_pyobj(0); n = 10; i = pyobj_to_bool(input())? 0 : 1; while (i < n) { if (i == 0) { y = x; x = mul(x, float_to_pyobj(0.5)); i = i + 1; print_any(y); return 0; Page 3 of 11
4 4. 10 points Translate the following P 4 program to GNU C. You may use the C functions declared in the Appendix. y = 1 f = lambda x: x + y y = 2 f(40) pyobj lambda0(pyobj fvs, pyobj x){ pyobj y; y = get(fvs, int_to_pyobj(0)); return add(x, get(y, int_to_pyobj(0))); int main() { pyobj f; pyobj y; y = make_list(1); put(y, int_to_pyobj(0), int_to_pyobj(1)); f = make_closure(lambda0, ({ pyobj fvs = make_list(1); put(fvs, int_to_pyobj(0), y); fvs; )); put(y_0, int_to_pyobj(0), int_to_pyobj(2)); print_pyobj(((pyobj(*)(pyobj, pyobj)) get_function_ptr(f))(get_free_vars(f), int_to_pyobj(40))); Page 4 of 11
5 5. 10 points Translate the following P 5 program to C. Perform partial evaluation to simplify the generated code for function calls. For example, in A() you know that A is a class, so you don t need to generate code that checks if it is a class. You may use the C functions declared in the Appendix. class A: def f(x): return x.y a = A() a.y = 21 print a.f() + A.f(a) pyobj lambda0(pyobj fvs, pyobj x) { return get_attribute(x, "y"); int main() { pyobj a; pyobj A; A = make_class_pyobj(make_list(0)); set_attribute(a, "f", make_closure(lambda0, make_list(0))); a = make_object(a); set_attribute(a, "y", int_to_pyobj(21)); pyobj af = get_attribute(a, "f"); pyobj caf = get_closure_from_bound_method(af); pyobj oaf = get_object_from_bound_method(f); pyobj Af = get_attribute(a, "f"); pyobj caf = get_closure_from_unbound_method(af); print_any(add(((pyobj(*)(pyobj, pyobj))get_function_ptr(caf))(get_free_vars(caf), oaf), ((pyobj(*)(pyobj, pyobj))get_function_ptr(caf))(get_free_vars(caf), a))); Page 5 of 11
6 6. 5 points Convert the following program to an equivalent program that does not contain any complex operators or operands nested inside of expressions or inside of returns. int factorial(int n) { if (n == 0) return 1; else return n * factorial(n - 1); int factorial(int n) { int t1, t2, t3; if (n == 0) return 1; else { t1 = n - 1; t2 = factorial(t1); t3 = n * t2; return t3; 7. 5 points Starting with your answer from the previous question, remove structured control flow statements, replacing them with labels and gotos or ifs whose bodies are only a goto. int factorial(int n) { int t1, t2, t3; if (n == 0) goto then_clause0; t1 = n - 1; t2 = factorial(t1); t3 = n * t2; return t3; then_clause0: return 1; Page 6 of 11
7 8. 15 points Starting with your answer from the previous question, convert to x86 assembly using the GNU Linux calling conventions. factorial: pushl subl cmpl je subl pushl call imull leave ret L2: leave ret %ebp %esp, %ebp $8, %esp $0, 8(%ebp) L2 8(%ebp), %eax $1, %eax %eax factorial $4, %esp %eax, -4(%ebp) 8(%ebp), %eax -4(%ebp), %eax %eax, -8(%ebp) -8(%ebp), %eax $1, %eax Page 7 of 11
8 9. 5 points Perform liveness analysis on the following intermediate representation and write down the live set for each statement. int f(int v) { int x, y, z; z = 1; y = v; push z; call g; z += y; x = eax; v = z; v += x; eax = v; int f(int v) { int x, y, z; z = 1; {v y = v; {v,z push z; {y,z call g; {y,z z += y; {eax,y,z x = eax; {eax,z v = z; {x,z v += x; {v,x eax = v; {v points Draw the interference graph for the program in question 9. x y v z eax points Draw the move graph for the program in question 9. x y v z eax Page 8 of 11
9 points Perform register allocation on the program in question 9 using only two general purpose registers: eax and ebx (in addition to the stack pointer esp and the base pointer ebp). Recall that eax is a caller-save register and ebx is a callee-save register. If necessary, iterate the process until no more spill code is generated. For each iteration, show the assignment of variables to registers and stack locations, the new version of the code resulting from spill, the new results of liveness analysis, and the new interference and move graph. At the end, write down the final x86 code. First round: x eax, y ebx, v 8(%ebp), z 4(%ebp) (could have spilled y instead of z and put z in ebx). Add spill code and do liveness again: int f(int v) { int x, y, z, t0; z = 1; {v y = v; {v,z push z; {y,z call g; {y,z z += y; {eax,y,z x = eax; {eax,z t0 = z; {x,z v = t0; {t0,x v += x; {v,x eax = v; {v Interference graph: t0 x y v z eax Move graph: t0 x y v z eax Second round: y ebx, x eax, t 0 ebx Page 9 of 11
10 Final x86 code: f: $1, -4(%ebp) %ebx, 8(%ebp) pushl -4(%ebp) call g addl %ebx, -4(%ebp) -4(%ebp), %ebx %ebx, 8(%ebp) addl %eax, 8(%ebp) 8(%ebp), %eax leave ret Page 10 of 11
11 Appendix: Runtime C Functions /* input/output */ pyobj input(); void print_any(pyobj); /* conversions */ char pyobj_to_bool(pyobj); pyobj int_to_pyobj(int); pyobj float_to_pyobj(double); /* arithmetic */ pyobj add(pyobj, pyobj); pyobj mul(pyobj, pyobj); /* list operations */ pyobj make_list(int); pybobj get(pyobj list, pyobj key); void put(pyobj list, pyobj key, pyobj value); /* closure operations */ pyobj make_closure(void* function_ptr, pyobj free_vars); void* get_function_ptr(pyobj closure); pyobj get_free_vars(pyobj closure); /* operations on classes and objects */ pyobj make_class(pyobj bases); pyobj make_object(pyobj class); pyobj get_attribute(pyobj object, char* attr); pyobj set_attribute(pyobj object, char* attr, pyobj value); pyobj get_closure_from_unbound_method(pyobj); pyobj get_class_from_unbound_method(pyobj); pyobj get_class_from_object(pyobj); pyobj get_closure_from_bound_method(pyobj); pyobj get_object_from_bound_method(pyobj); Page 11 of 11
Assignment 11: functions, calling conventions, and the stack
Assignment 11: functions, calling conventions, and the stack ECEN 4553 & 5013, CSCI 4555 & 5525 Prof. Jeremy G. Siek December 5, 2008 The goal of this week s assignment is to remove function definitions
More informationIntroduction to Compilers Professor Jeremy Siek
Professor Jeremy Siek This exam has 9 questions, for a total of 100 points. 1. 5 points What is the output of the following Python program, x = input() print x + input() % input(), False, True given the
More information4) C = 96 * B 5) 1 and 3 only 6) 2 and 4 only
Instructions: The following questions use the AT&T (GNU) syntax for x86-32 assembly code, as in the course notes. Submit your answers to these questions to the Curator as OQ05 by the posted due date and
More informationAssembly Language: Function Calls
Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and returning Passing parameters Storing local variables Handling registers without interference
More informationAssembly Language: Function Calls" Goals of this Lecture"
Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and returning" Passing parameters" Storing local variables" Handling registers without interference"
More informationCSE P 501 Exam 8/5/04 Sample Solution. 1. (10 points) Write a regular expression or regular expressions that generate the following sets of strings.
1. (10 points) Write a regular ression or regular ressions that generate the following sets of strings. (a) (5 points) All strings containing a s, b s, and c s with at least one a and at least one b. [abc]*a[abc]*b[abc]*
More informationAssembly Language: Function Calls" Goals of this Lecture"
Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and urning" Passing parameters" Storing local variables" Handling registers without interference"
More informationCIS 341 Midterm February 28, Name (printed): Pennkey (login id): SOLUTIONS
CIS 341 Midterm February 28, 2013 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
More informationCIT Week13 Lecture
CIT 3136 - Week13 Lecture Runtime Environments During execution, allocation must be maintained by the generated code that is compatible with the scope and lifetime rules of the language. Typically there
More informationAssembly Language: Function Calls. Goals of this Lecture. Function Call Problems
Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and urning Passing parameters Storing local variables Handling registers without interference Returning
More informationProcedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29
Procedure Calls Young W. Lim 2017-08-21 Mon Young W. Lim Procedure Calls 2017-08-21 Mon 1 / 29 Outline 1 Introduction Based on Stack Background Transferring Control Register Usage Conventions Procedure
More informationFunction Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)
Function Calls COS 217 Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site) 1 Goals of Today s Lecture Finishing introduction to assembly language o EFLAGS register
More informationCOMP 210 Example Question Exam 2 (Solutions at the bottom)
_ Problem 1. COMP 210 Example Question Exam 2 (Solutions at the bottom) This question will test your ability to reconstruct C code from the assembled output. On the opposing page, there is asm code for
More informationYou may work with a partner on this quiz; both of you must submit your answers.
Instructions: Choose the best answer for each of the following questions. It is possible that several answers are partially correct, but one answer is best. It is also possible that several answers are
More informationWhat the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.
C Flow Control David Chisnall February 1, 2011 Outline What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope Disclaimer! These slides contain a lot of
More informationProcedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27
Procedure Calls Young W. Lim 2016-11-05 Sat Young W. Lim Procedure Calls 2016-11-05 Sat 1 / 27 Outline 1 Introduction References Stack Background Transferring Control Register Usage Conventions Procedure
More informationLecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1
Lecture #16: Introduction to Runtime Organization Last modified: Fri Mar 19 00:17:19 2010 CS164: Lecture #16 1 Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces
More informationCSC 2400: Computing Systems. X86 Assembly: Function Calls"
CSC 24: Computing Systems X86 Assembly: Function Calls" 1 Lecture Goals! Challenges of supporting functions" Providing information for the called function" Function arguments and local variables" Allowing
More informationCSC 2400: Computing Systems. X86 Assembly: Function Calls
CSC 24: Computing Systems X86 Assembly: Function Calls 1 Lecture Goals Challenges of supporting functions Providing information for the called function Function arguments and local variables Allowing the
More informationSystem Programming and Computer Architecture (Fall 2009)
System Programming and Computer Architecture (Fall 2009) Recitation 2 October 8 th, 2009 Zaheer Chothia Email: zchothia@student.ethz.ch Web: http://n.ethz.ch/~zchothia/ Topics for Today Classroom Exercise
More informationCS 33: Week 3 Discussion. x86 Assembly (v1.0) Section 1G
CS 33: Week 3 Discussion x86 Assembly (v1.0) Section 1G Announcements - HW2 due Sunday - MT1 this Thursday! - Lab2 out Info Name: Eric Kim (Section 1G, 2-4 PM, BH 5419) Office Hours (Boelter 2432) - Wed
More informationMachine-level Programming (3)
Machine-level Programming (3) Procedures A: call A call A return Two issues How to return to the correct position? How to pass arguments and return values between callee to caller? 2 Procedure Control
More informationRegister Allocation, iii. Bringing in functions & using spilling & coalescing
Register Allocation, iii Bringing in functions & using spilling & coalescing 1 Function Calls ;; f(x) = let y = g(x) ;; in h(y+x) + y*5 (:f (x
More informationIntegers and variables
CHAPTER 1 Integers and variables The main concepts in this chapter are abstract syntax trees: Inside the compiler we represent programs with a data-structure called an abstract syntax tree (AST). recursive
More informationAssembly 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 IA-32 (1) Characteristics Region of memory managed with stack discipline
More informationIntegers and variables
CHAPTER 1 Integers and variables The main concepts in this chapter are abstract syntax trees: Inside the compiler, we represent programs with a data-structure called an abstract syntax tree, which is abbreviated
More informationASSEMBLY III: PROCEDURES. Jo, Heeseung
ASSEMBLY III: PROCEDURES Jo, Heeseung IA-32 STACK (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top
More informationAssembly III: Procedures. Jo, Heeseung
Assembly III: Procedures Jo, Heeseung IA-32 Stack (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top
More informationEECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution
1. (40 points) Write the following subroutine in x86 assembly: Recall that: int f(int v1, int v2, int v3) { int x = v1 + v2; urn (x + v3) * (x v3); Subroutine arguments are passed on the stack, and can
More informationCredits 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 2 nd Edition by Bryant and O'Hallaron
More informationCPS104 Recitation: Assembly Programming
CPS104 Recitation: Assembly Programming Alexandru Duțu 1 Facts OS kernel and embedded software engineers use assembly for some parts of their code some OSes had their entire GUIs written in assembly in
More informationCPSC W Term 2 Problem Set #3 - Solution
1. (a) int gcd(int a, int b) { if (a == b) urn a; else if (a > b) urn gcd(a - b, b); else urn gcd(a, b - a); CPSC 313 06W Term 2 Problem Set #3 - Solution.file "gcdrec.c".globl gcd.type gcd, @function
More informationLecture Outline. Code Generation. Lecture 30. Example of a Stack Machine Program. Stack Machines
Lecture Outline Code Generation Lecture 30 (based on slides by R. Bodik) Stack machines The MIPS assembly language The x86 assembly language A simple source language Stack-machine implementation of the
More informationAS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions
CS220 Logic Design Outline Calling Conventions Multi-module Programs 1 Calling and Returning We have already seen how the call instruction is used to execute a subprogram. call pushes the address of the
More informationIntroduction to Computer Systems. Exam 1. February 22, This is an open-book exam. Notes are permitted, but not computers.
15-213 Introduction to Computer Systems Exam 1 February 22, 2005 Name: Andrew User ID: Recitation Section: This is an open-book exam. Notes are permitted, but not computers. Write your answer legibly in
More informationCS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016
CS 31: Intro to Systems Functions and the Stack Martin Gagne Swarthmore College February 23, 2016 Reminders Late policy: you do not have to send me an email to inform me of a late submission before the
More informationCode Generation. Lecture 30
Code Generation Lecture 30 (based on slides by R. Bodik) 11/14/06 Prof. Hilfinger CS164 Lecture 30 1 Lecture Outline Stack machines The MIPS assembly language The x86 assembly language A simple source
More informationX86 Stack Calling Function POV
X86 Stack Calling Function POV Computer Systems Section 3.7 Stack Frame Reg Value ebp xffff FFF0 esp xffff FFE0 eax x0000 000E Memory Address Value xffff FFF8 xffff FFF4 x0000 0004 xffff FFF4 x0000 0003
More informationCSE P 501 Exam 8/5/04
Name There are 7 questions worth a total of 65 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: Course
More informationCS213. Machine-Level Programming III: Procedures
CS213 Machine-Level Programming III: Procedures Topics IA32 stack discipline Register saving conventions Creating pointers to local variables IA32 Region of memory managed with stack discipline Grows toward
More informationx86 assembly CS449 Fall 2017
x86 assembly CS449 Fall 2017 x86 is a CISC CISC (Complex Instruction Set Computer) e.g. x86 Hundreds of (complex) instructions Only a handful of registers RISC (Reduced Instruction Set Computer) e.g. MIPS
More informationThe course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002
15-213 The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables class07.ppt
More informationCPEG421/621 Tutorial
CPEG421/621 Tutorial Compiler data representation system call interface calling convention Assembler object file format object code model Linker program initialization exception handling relocation model
More informationIntroduction to Computer Systems. Exam 1. February 22, Model Solution fp
15-213 Introduction to Computer Systems Exam 1 February 22, 2005 Name: Andrew User ID: Recitation Section: Model Solution fp This is an open-book exam. Notes are permitted, but not computers. Write your
More informationCS241 Computer Organization Spring 2015 IA
CS241 Computer Organization Spring 2015 IA-32 2-10 2015 Outline! Review HW#3 and Quiz#1! More on Assembly (IA32) move instruction (mov) memory address computation arithmetic & logic instructions (add,
More informationCMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang
Project 3 Questions CMSC 313 Lecture 12 How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP
More informationTHEORY OF COMPILATION
Lecture 10 Activation Records THEORY OF COMPILATION EranYahav www.cs.technion.ac.il/~yahave/tocs2011/compilers-lec10.pptx Reference: Dragon 7.1,7.2. MCD 6.3,6.4.2 1 You are here Compiler txt Source Lexical
More informationFunctions CHAPTER 5. FIGURE 1. Concrete syntax for the P 2 subset of Python. (In addition to that of P 1.)
CHAPTER 5 Functions The main ideas in this chapter are: first-class functions: functions are values that can be passed as arguments to other functions, returned from functions, stored in lists and dictionaries,
More informationCredits 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 2 nd Edition by Bryant and O'Hallaron
More informationMachine-Level Programming II: Control and Arithmetic
Machine-Level Programming II: Control and Arithmetic CSCI 2400: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides 1 Today Complete addressing mode, address
More informationQuestion 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110
Questions 1 Question 4.1 1: (Solution, p 5) Define the fetch-execute cycle as it relates to a computer processing a program. Your definition should describe the primary purpose of each phase. Question
More informationDigital Forensics Lecture 3 - Reverse Engineering
Digital Forensics Lecture 3 - Reverse Engineering Low-Level Software Akbar S. Namin Texas Tech University Spring 2017 Reverse Engineering High-Level Software Low-level aspects of software are often the
More informationCompilation /15a Lecture 7. Activation Records Noam Rinetzky
Compilation 0368-3133 2014/15a Lecture 7 Activation Records Noam Rinetzky 1 Code generation for procedure calls (+ a few words on the runtime system) 2 Code generation for procedure calls Compile time
More informationCS 3843 Final Exam Fall 2012
CS 3843 Final Exam Fall 2012 Name (Last), (First) ID Please indicate your session: Morning Afternoon You may use a calculator and two sheets of notes on this exam, but no other materials and no computer.
More informationSungkyunkwan University
Switch statements IA 32 Procedures Stack Structure Calling Conventions Illustrations of Recursion & Pointers long switch_eg (long x, long y, long z) { long w = 1; switch(x) { case 1: w = y*z; break; case
More informationStatus. Lecture #15: Introduction to Runtime Organization. Run-time environments. Code Generation Goals and Considerations
Lecture #15: Introduction to Runtime Organization Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces trees Detects & eliminates ill-formed parse trees Static semantic
More informationComputer Systems Organization V Fall 2009
Computer Systems Organization V22.0201 Fall 2009 Sample Midterm Exam ANSWERS 1. True/False. Circle the appropriate choice. (a) T (b) F At most one operand of an x86 assembly instruction can be an memory
More informationCompilation 2014 Code Generation Issues
Compilation 2014 Code Generation Issues Aslan Askarov aslan@cs.au.dk Based on slides by E. Ernst Administrativia November 28 guest lecture by Filip Sieczkowski (AU) Memory Models December 12 guest lecture
More informationCS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016
CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College February 9, 2016 Reading Quiz Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between
More informationCS61 Section Solutions 3
CS61 Section Solutions 3 (Week of 10/1-10/5) 1. Assembly Operand Specifiers 2. Condition Codes 3. Jumps 4. Control Flow Loops 5. Procedure Calls 1. Assembly Operand Specifiers Q1 Operand Value %eax 0x104
More informationCompiler Construction D7011E
Compiler Construction D7011E Lecture 8: Introduction to code generation Viktor Leijon Slides largely by Johan Nordlander with material generously provided by Mark P. Jones. 1 What is a Compiler? Compilers
More informationCS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018
CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College September 25, 2018 Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between programmer
More informationW4118: PC Hardware and x86. Junfeng Yang
W4118: PC Hardware and x86 Junfeng Yang A PC How to make it do something useful? 2 Outline PC organization x86 instruction set gcc calling conventions PC emulation 3 PC board 4 PC organization One or more
More informationImplementing Threads. Operating Systems In Depth II 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.
Implementing Threads Operating Systems In Depth II 1 Copyright 2018 Thomas W Doeppner All rights reserved The Unix Address Space stack dynamic bss data text Operating Systems In Depth II 2 Copyright 2018
More informationAssembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012
19:211 Computer Architecture Lecture 10 Fall 20 Topics:Chapter 3 Assembly Language 3.2 Register Transfer 3. ALU 3.5 Assembly level Programming We are now familiar with high level programming languages
More informationCS , Fall 2004 Exam 1
Andrew login ID: Full Name: CS 15-213, Fall 2004 Exam 1 Tuesday October 12, 2004 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front.
More information1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.
1 /* file cpuid2.s */ 2.section.data 3 output: 4.asciz "The processor Vendor ID is %s \n" 5.section.bss 6.lcomm buffer, 12 7.section.text 8.globl _start 9 _start: 10 movl $0, %eax 11 cpuid 12 movl $buffer,
More informationIntel assembly language using gcc
QOTD Intel assembly language using gcc Assembly language programming is difficult. Make no mistake about that. It is not for wimps and weaklings. - Tanenbaum s 6th, page 519 These notes are a supplement
More informationCAS CS Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm
CAS CS 210 - Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm This problem set is to be completed individually. Explain how you got to your answers
More informationLab 10: Introduction to x86 Assembly
CS342 Computer Security Handout # 8 Prof. Lyn Turbak Wednesday, Nov. 07, 2012 Wellesley College Revised Nov. 09, 2012 Lab 10: Introduction to x86 Assembly Revisions: Nov. 9 The sos O3.s file on p. 10 was
More informationFinal exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Dec 20, Student's name: Student ID:
Fall term 2012 KAIST EE209 Programming Structures for EE Final exam Thursday Dec 20, 2012 Student's name: Student ID: The exam is closed book and notes. Read the questions carefully and focus your answers
More informationCS , Fall 2001 Exam 1
Andrew login ID: Full Name: CS 15-213, Fall 2001 Exam 1 October 9, 2001 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write
More informationFinal Exam. Fall Semester 2015 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:
Fall Semester 2015 KAIST EE209 Programming Structures for Electrical Engineering Final Exam Name: This exam is closed book and notes Read the questions carefully and focus your answers on what has been
More informationSystems I. Machine-Level Programming V: Procedures
Systems I Machine-Level Programming V: Procedures Topics abstraction and implementation IA32 stack discipline Procedural Memory Usage void swap(int *xp, int *yp) int t0 = *xp; int t1 = *yp; *xp = t1; *yp
More informationCompilers Crash Course
Compilers Crash Course Prof. Michael Clarkson CSci 6907.85 Spring 2014 Slides Acknowledgment: Prof. Andrew Myers (Cornell) What are Compilers? Translators from one representation of program code to another
More informationX86 Assembly -Procedure II:1
X86 Assembly -Procedure II:1 IA32 Object Code Setup Label.L61 becomes address 0x8048630 Label.L62 becomes address 0x80488dc Assembly Code switch_eg:... ja.l61 # if > goto default jmp *.L62(,%edx,4) # goto
More informationAssembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction
Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction E I P CPU isters Condition Codes Addresses Data Instructions Memory Object Code Program Data OS Data Topics Assembly Programmer
More informationInstructor: Alvin R. Lebeck
X86 Assembly Programming with GNU assembler Lecture 7 Instructor: Alvin R. Lebeck Some Slides based on those from Randy Bryant and Dave O Hallaron Admin Reading: Chapter 3 Note about pointers: You must
More informationCS 2505 Computer Organization I
Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other computing devices may
More informationCS , Fall 2002 Exam 1
Andrew login ID: Full Name: CS 15-213, Fall 2002 Exam 1 October 8, 2002 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write
More informationCS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed
Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices
More informationChapter 10 Implementing Subprograms
Chapter 10 Implementing Subprograms The General Semantics of Calls and Returns - Definition: The subprogram call and return operations of a language are together called its subprogram linkage Implementing
More informationMachine-Level Programming III: Procedures
Machine-Level Programming III: Procedures IA32 Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address address of top element Bottom Increasing
More informationFunction 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 informationFunctions CHAPTER 5. FIGURE 1. Concrete syntax for the P 2 subset of Python. (In addition to that of P 1.)
CHAPTER 5 Functions The main ideas in this chapter are: first-class functions: functions are values that can be passed as arguments to other functions, returned from functions, stored in lists and dictionaries,
More informationCS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017
CS 31: Intro to Systems ISAs and Assembly Martin Gagné Swarthmore College February 7, 2017 ANNOUNCEMENT All labs will meet in SCI 252 (the robot lab) tomorrow. Overview How to directly interact with hardware
More information1 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 informationIA32 Stack. Lecture 5 Machine-Level Programming III: Procedures. IA32 Stack Popping. IA32 Stack Pushing. Topics. Pushing. Popping
Lecture 5 Machine-Level Programming III: Procedures Topics IA32 stack discipline Register saving conventions Creating pointers to local variables IA32 Region of memory managed with stack discipline Grows
More informationadministrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?
administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions? exam on Wednesday today s material not on the exam 1 Assembly Assembly is programming
More informationWhat is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation
Compiler Construction SMD163 Lecture 8: Introduction to code generation Viktor Leijon & Peter Jonsson with slides by Johan Nordlander Contains material generously provided by Mark P. Jones What is a Compiler?
More information(2) Accidentally using the wrong instance of a variable (sometimes very hard one to find).
Scope and storage class of variables The scope of a variable refers to those portions of a program wherein it may be accessed. Failure to understand scoping rules can lead to two problems: (1) Syntax errors
More informationAssembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University
Assembly I: Basic Operations Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Moving Data (1) Moving data: movl source, dest Move 4-byte ( long )
More informationCSC 2400: Computer Systems. Using the Stack for Function Calls
CSC 24: Computer Systems Using the Stack for Function Calls Lecture Goals Challenges of supporting functions! Providing information for the called function Function arguments and local variables! Allowing
More informationAn Elegant Weapon for a More Civilized Age
An Elegant Weapon for a More Civilized Age Solving an Easy Problem What are the input types? What is the output type? Give example input/output pairs Which input represents the domain of the recursion,
More informationCMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009
CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009 Name Score out of 70 UMBC Username Notes: a. Please write clearly. Unreadable answers receive no credit. b. For TRUE/FALSE questions, write the
More informationGiving credit where credit is due
CSCE 230J Computer Organization Machine-Level Programming III: Procedures Dr. Steve Goddard goddard@cse.unl.edu Giving credit where credit is due Most of slides for this lecture are based on slides created
More informationCMSC 313 Lecture 12 [draft] How C functions pass parameters
CMSC 313 Lecture 12 [draft] How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP removes an
More informationLecture #19: Code Generation
Lecture #19: Code Generation [This lecture adopted in part from notes by R. Bodik] Last modified: Wed Oct 31 12:18:49 2012 CS164: Lecture #19 1 Intermediate Languages and Machine Languages From trees such
More informationIntermediate Languages and Machine Languages. Lecture #31: Code Generation. Stack Machine with Accumulator. Stack Machines as Virtual Machines
Lecture #31: Code Generation [This lecture adopted in part from notes by R. Bodik] Intermediate Languages and Machine Languages From trees such as output from project #2, could produce machine language
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 16, SPRING 2013 TOPICS TODAY Project 6 Perils & Pitfalls of Memory Allocation C Function Call Conventions in Assembly Language PERILS
More information