CS 4110 Programming Languages & Logics. Lecture 35 Typed Assembly Language
|
|
- Oswin Cannon
- 5 years ago
- Views:
Transcription
1 CS 4110 Programming Languages & Logics Lecture 35 Typed Assembly Language 1 December 2014
2 Announcements 2 Foster Office Hours today 4-5pm Optional Homework 10 out Final practice problems out this week
3 Schedule 3 One and a half weeks ago... Typed Assembly Language Last Monday Polymorphism Stack Types Today Compilation
4 Certified Compilation 4 An automatic way to generate certifiable low-level code Type safety implies memory, security properties
5 Certified Compilation 4 An automatic way to generate certifiable low-level code Type safety implies memory, security properties Tiny Source language
6 Certified Compilation 4 An automatic way to generate certifiable low-level code Type safety implies memory, security properties Tiny Source language Typed Assembly Language Compiler target
7 Certified Compilation 4 An automatic way to generate certifiable low-level code Type safety implies memory, security properties Tiny Source language Typed Assembly Language Compiler target Optimized Typed Assembly Language Optimizer target
8 The Tiny Language 5 Features Integer expressions Conditionals Recursive functions Function pointers (but no closures) A strong, static type system
9 The Tiny Language 5 Features Integer expressions Conditionals Recursive functions Function pointers (but no closures) A strong, static type system Example program letrec fun fact (n:int) : int = if n = 0 then 1 else n * fact (n 1) in fact (42)
10 Tiny Type System 6 Expressions Φ x : Φ(x)
11 Tiny Type System 6 Expressions Φ x : Φ(x) Φ f : Φ(f)
12 Tiny Type System 6 Expressions Φ x : Φ(x) Φ f : Φ(f) Φ n : int
13 Tiny Type System 6 Expressions Φ x : Φ(x) Φ f : Φ(f) Φ n : int Φ e 1 : int Φ e 2 : int Φ e 1 + e 2 : int
14 Tiny Type System 6 Expressions Φ x : Φ(x) Φ f : Φ(f) Φ n : int Φ e 1 : int Φ e 1 + e 2 : int Φ e 2 : int Φ e 1 : τ 1 τ 2 Φ e 2 : τ 1 Φ e 1 e 2 : τ 2
15 Tiny Type System 6 Expressions Φ x : Φ(x) Φ f : Φ(f) Φ n : int Φ e 1 : int Φ e 1 + e 2 : int Φ e 2 : int Φ e 1 : τ 1 τ 2 Φ e 2 : τ 1 Φ e 1 e 2 : τ 2 Φ e 1 : int Φ e 2 : τ Φ e 3 : τ Φ if e 1 = 0 then e 2 else e 3 : τ
16 Tiny Type System 6 Expressions Φ x : Φ(x) Φ f : Φ(f) Φ n : int Φ e 1 : int Φ e 1 + e 2 : int Φ e 2 : int Φ e 1 : τ 1 τ 2 Φ e 2 : τ 1 Φ e 1 e 2 : τ 2 Φ e 1 : int Φ e 2 : τ Φ e 3 : τ Φ if e 1 = 0 then e 2 else e 3 : τ Φ e 1 : τ 1 Φ, x : τ 1 e 2 : τ 2 Φ let x = e 1 in e 2 : τ 1
17 Tiny Type System 7 Declarations Φ, x : τ 1 e : τ 2 Φ fun f(x : τ 1 ) : τ 2 = e : (f : τ 1 τ 2 )
18 Tiny Type System 7 Declarations Φ, x : τ 1 e : τ 2 Φ fun f(x : τ 1 ) : τ 2 = e : (f : τ 1 τ 2 ) Programs Φ = f 1 : τ 11 τ 12,..., f k : τ k1 τ k2 Φ d i : (f i : τ i1 τ i2 ) Φ e : int letrec d 1 d k in e
19 Tiny Type System 7 Declarations Φ, x : τ 1 e : τ 2 Φ fun f(x : τ 1 ) : τ 2 = e : (f : τ 1 τ 2 ) Programs Φ = f 1 : τ 11 τ 12,..., f k : τ k1 τ k2 Φ d i : (f i : τ i1 τ i2 ) Φ e : int letrec d 1 d k in e Exercise: Check that fact is well typed
20 Type-preserving Compilation 8 Most compilers consist of a series of transformations In our compiler, each step will propagate types A transformation consists of two sub-translations: From source types to target types From source terms to target terms After each step, can typecheck the intermediate output code to detect errors in the compiler Key correctness property will be that transformations preserve types (as well as semantics)
21 Type Translation 9 T [[ ]] maps Tiny types to TAL Types
22 Type Translation 9 T [[ ]] maps Tiny types to TAL Types Integers: T [[int]] = int
23 Type Translation 9 T [[ ]] maps Tiny types to TAL Types Integers: T [[int]] = int Functions: Caller pushes argument and return address on stack Callee pops the return address and argument and places result in ra T [[τ 1 τ 2 ]] = ρ.{sp : K[[τ 2, ρ]] :: T [[τ 1 ]] :: ρ} {} where K[[τ, σ]] = {sp : σ, r a : T [[τ]]} {} K[[τ]] = {r a : T [[τ]]} {}
24 Expression Translation 10 E[[ ]] maps Tiny expressions (really typing derivations) to labeled code blocks
25 Expression Translation 10 E[[ ]] maps Tiny expressions (really typing derivations) to labeled code blocks We use the stack extensively: To evaluate an expression, evaluate subexpressions then push them onto the stack Return final value in ra M maps expression variables to stack offsets I(M) increments the offset associated with each variable in M Overall, uses just two registers, r a and r t, and the stack Shape of the translation is E[[e]] M,σ = J, where J is a sequence of typed, labeled blocks. Write L f for the TAL label of function f
26 Expression Translation 11 Expression variables E[[x]] M,σ = sld r a, M(x)
27 Expression Translation 11 Expression variables E[[x]] M,σ = sld r a, M(x) Function variables E[[f]] M,σ = mov r a, L f
28 Expression Translation 11 Expression variables E[[x]] M,σ = sld r a, M(x) Function variables E[[f]] M,σ = mov r a, L f Integers E[[n]] M,σ = mov r a, n
29 Expression Translation 11 Expression variables E[[x]] M,σ = sld r a, M(x) Function variables E[[f]] M,σ = mov r a, L f Addition E[[e 1 + e 2 ]] M,σ = E[[e 1 ]] M,σ push r a E[[e 2 ]] I(M),int :: σ pop r t add r a, r t, r a Integers E[[n]] M,σ = mov r a, n
30 Expression Translation 12 Application E[[e 1 e 2 ]] M,σ = E[[e 1 ]] M,σ push r a E[[e 2 ]] I(M),T [[τ1 τ 2 ]] :: σ pop r t push r a push L r [ρ] jmp r t [σ] L r : ρ. K[[τ 2, σ]] where Φ e 1 : τ 1 τ 2 and L r fresh
31 Expression Translation 13 Conditional E[[if e 1 = 0 then e 2 else e 3 ]] M,σ = E[[e 1 ]] M,σ bneq r a, L else [ρ] E[[e 2 ]] M,σ jmp L end [ρ] L else : ρ.{sp : σ} {} E[[e 3 ]] M,σ jmp L end [ρ] L end : ρ.k[[τ, σ]] where Φ e 2 : τ and Φ e 2 : τ and L else and L end fresh
32 Declaration Translation 14 Function F[[fun f (x : τ 1 ) : τ 2 = e]] = L f : T [[τ 1 τ 2 ]] E[[e 2 ]] x := 2,K[[τ2,ρ]] :: T [[τ 1 ]] :: ρ pop r t sfree 1 jmp r t
33 Program Translation 15 Program P[[letrec d 1 d k in e]] = F[[d 1 ]]. F[[d k ]] L main : ρ.{sp : K[[int, ρ]] :: ρ} {} E[[e]],K[[int,ρ]] :: ρ pop r t jmp r t To run the program, push return address on stack and jump to L main Result is returned in r a
34 Factorial L fact : ρ. {sp : K[[int]] :: int :: ρ} sld r a,2 bneq r a,l else [ρ] mov r a,1 jmp L end L else : ρ. {sp : K[[int]] :: int :: ρ} sld r a,2 push r a mov r a,l fact push r a sld r a,4 push r a mov r a,1 pop r t sub r a,r t,r a pop r t push L r [ρ] jmp r t [int :: K[[int, ρ]] :: int :: ρ] 16
35 Factorial L fact : ρ. {sp : K[[int]] :: int :: ρ} sld r a,2 bneq r a,l else [ρ] mov r a,1 jmp L end L else : ρ. {sp : K[[int]] :: int :: ρ} sld r a,2 push r a mov r a,l fact push r a sld r a,4 push r a mov r a,1 pop r t sub r a,r t,r a pop r t push L r [ρ] jmp r t [int :: K[[int, ρ]] :: int :: ρ] L r : ρ. {sp : K[[int]] :: int :: ρ, r a : int} pop r t mul r a,r t,r t jmp L end [ρ] L end : ρ. {sp : K[[int]] :: int :: ρ, r a : int} pop r t sfree 1 jmp r t 16
36 Compiler properties 17 Theorem If P then there exists Ψ such that P[[P]] : Ψ Proof by induction on P... Main idea: We don t have to trust the compiler because we can typecheck the assembly code emitted as output!
37 Optimizations Almost any compiler will produce better code than ours! (But how many compilers fit on four slides?) The type system makes it possible to implement many standard optimizations to generate better code: Instruction selection and scheduling Register allocation Common subexpression elimination Redundant load/store elimination Strength reduction Loop-invariant removal Tail-calls and others... Types do not interfere with the most common optimizations 18
38 Tail-call Optimization 19 A crucial optimization for functional languages Applies when the final operation in a function f is a call to another function g Instead of having f push the return address onto the stack and engage in the normal calling sequence, f pops all of its temporary values, jumps directly to g and never returns!
39 Tail-call Optimization 20 Unoptimized code L f : ρ. {sp : K[[τ, ρ]] :: τ f :: ρ, r a : τ g } {} salloc 2 % setup stack frame sst L r % push return address sst r a,2 % push argument jmp L g [τ :: τ f :: ρ] L r : ρ. {sp : τ :: τ f :: ρ, r a : τ} {} pop r t % pop return address sfree 1 % discard f s argument jmp r t % return Optimized code L f : ρ. {sp : K[[τ, ρ]] :: τ f :: ρ, r a : τ g } {} sst r a,2 jmp L g [ρ] % g returns to f s caller
CS 4110 Programming Languages & Logics
CS 4110 Programming Languages & Logics Lecture 38 Typed Assembly Language 30 November 2012 Schedule 2 Monday Typed Assembly Language Wednesday Polymorphism Stack Types Today Compilation Course Review Certi
More informationCOMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture
COMP 303 Computer Architecture Lecture 3 Comp 303 Computer Architecture 1 Supporting procedures in computer hardware The execution of a procedure Place parameters in a place where the procedure can access
More informationCode Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline.
The Main Idea of Today s Lecture Code Generation We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?
More informationWe can emit stack-machine-style code for expressions via recursion
Code Generation The Main Idea of Today s Lecture We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?
More informationCompilers and computer architecture: A realistic compiler to MIPS
1 / 1 Compilers and computer architecture: A realistic compiler to MIPS Martin Berger November 2017 Recall the function of compilers 2 / 1 3 / 1 Recall the structure of compilers Source program Lexical
More informationSubroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}
Subroutines Also called procedures or functions Example C code: int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;} // subroutine converts Celsius to kelvin int celtokel(int i) { return (i
More informationLecture 5. Announcements: Today: Finish up functions in MIPS
Lecture 5 Announcements: Today: Finish up functions in MIPS 1 Control flow in C Invoking a function changes the control flow of a program twice. 1. Calling the function 2. Returning from the function In
More informationLectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS
Lectures 5 Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS 1 OOPS - What does this C code do? int foo(char *s) { int L = 0; while (*s++) { ++L; } return L; } 2
More informationScope, Functions, and Storage Management
Scope, Functions, and Storage Management Implementing Functions and Blocks cs3723 1 Simplified Machine Model (Compare To List Abstract Machine) Registers Code Data Program Counter (current instruction)
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter
More informationCourse Administration
Fall 2018 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture Introduction 4/4 Avinash Karanth Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701
More informationCSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.
CSCI 402: Computer Architectures Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI Recall Big endian, little endian Memory alignment Unsigned
More informationCS143 - Written Assignment 4 Reference Solutions
CS143 - Written Assignment 4 Reference Solutions 1. Consider the following program in Cool, representing a slightly over-engineered implementation which calculates the factorial of 3 using an operator
More informationStack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15
Stack Frames Geoffrey Brown Bryce Himebaugh Indiana University September 2, 2016 Geoffrey Brown, Bryce Himebaugh 2015 September 2, 2016 1 / 15 Outline Preserving Registers Saving and Restoring Registers
More informationFunctions in MIPS. Functions in MIPS 1
Functions in MIPS We ll talk about the 3 steps in handling function calls: 1. The program s flow of control must be changed. 2. Arguments and return values are passed back and forth. 3. Local variables
More informationEE 361 University of Hawaii Fall
C functions Road Map Computation flow Implementation using MIPS instructions Useful new instructions Addressing modes Stack data structure 1 EE 361 University of Hawaii Implementation of C functions and
More informationThe plot thickens. Some MIPS instructions you can write cannot be translated to a 32-bit number
The plot thickens Some MIPS instructions you can write cannot be translated to a 32-bit number some reasons why 1) constants are too big 2) relative addresses are too big 3) absolute addresses are outside
More informationRun-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13
Run-time Environments Lecture 13 by Prof. Vijay Ganesh) Lecture 13 1 What have we covered so far? We have covered the front-end phases Lexical analysis (Lexer, regular expressions,...) Parsing (CFG, Top-down,
More informationCS64 Week 5 Lecture 1. Kyle Dewey
CS64 Week 5 Lecture 1 Kyle Dewey Overview More branches in MIPS Memory in MIPS MIPS Calling Convention More Branches in MIPS else_if.asm nested_if.asm nested_else_if.asm Memory in MIPS Accessing Memory
More informationInstruction Set Architecture
Computer Architecture Instruction Set Architecture Lynn Choi Korea University Machine Language Programming language High-level programming languages Procedural languages: C, PASCAL, FORTRAN Object-oriented
More informationControl Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary
Control Instructions Computer Organization Architectures for Embedded Computing Thursday, 26 September 2013 Many slides adapted from: Computer Organization and Design, Patterson & Hennessy 4th Edition,
More informationControl Instructions
Control Instructions Tuesday 22 September 15 Many slides adapted from: and Design, Patterson & Hennessy 5th Edition, 2014, MK and from Prof. Mary Jane Irwin, PSU Summary Previous Class Instruction Set
More informationCS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri
CS356: Discussion #6 Assembly Procedures and Arrays Marco Paolieri (paolieri@usc.edu) Procedures Functions are a key abstraction in software They break down a problem into subproblems. Reusable functionality:
More informationCOMP2611: Computer Organization MIPS function and recursion
COMP2611 Fall2015 COMP2611: Computer Organization MIPS function and recursion Overview 2 You will learn the following in this lab: how to use MIPS functions in a program; the concept of recursion; how
More informationCSE Lecture In Class Example Handout
CSE 30321 Lecture 07-09 In Class Example Handout Part A: A Simple, MIPS-based Procedure: Swap Procedure Example: Let s write the MIPS code for the following statement (and function call): if (A[i] > A
More informationTopic 3-a. Calling Convention 2/29/2008 1
Topic 3-a Calling Convention 2/29/2008 1 Calling Convention Calling convention is a standardized method for a program to pass parameters to a procedure and receive result values back from it. 2/29/2008
More informationToday. Putting it all together
Today! One complete example To put together the snippets of assembly code we have seen! Functions in MIPS Slides adapted from Josep Torrellas, Craig Zilles, and Howard Huang Putting it all together! Count
More informationCS153: Compilers Lecture 8: Compiling Calls
CS153: Compilers Lecture 8: Compiling Calls Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 2 out Due Thu Oct 4 (7 days) Project 3 out Due Tuesday Oct 9 (12 days) Reminder:
More informationCS 61C: Great Ideas in Computer Architecture (Machine Structures) More MIPS Machine Language
CS 61C: Great Ideas in Computer Architecture (Machine Structures) More MIPS Machine Language Instructors: Randy H. Katz David A. PaGerson hgp://inst.eecs.berkeley.edu/~cs61c/sp11 1 2 Machine Interpreta4on
More informationCS153: Compilers Lecture 15: Local Optimization
CS153: Compilers Lecture 15: Local Optimization Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 4 out Due Thursday Oct 25 (2 days) Project 5 out Due Tuesday Nov 13 (21 days)
More informationG Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing
More informationCode Generation. Lecture 12
Code Generation Lecture 12 1 Lecture Outline Topic 1: Basic Code Generation The MIPS assembly language A simple source language Stack-machine implementation of the simple language Topic 2: Code Generation
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 informationLecture Outline. Topic 1: Basic Code Generation. Code Generation. Lecture 12. Topic 2: Code Generation for Objects. Simulating a Stack Machine
Lecture Outline Code Generation Lecture 12 Topic 1: Basic Code Generation The MIPS assembly language A simple source language Stack-machine implementation of the simple language Topic 2: Code Generation
More informationFunction Calling Conventions 1 CS 64: Computer Organization and Design Logic Lecture #9
Function Calling Conventions 1 CS 64: Computer Organization and Design Logic Lecture #9 Ziad Matni Dept. of Computer Science, UCSB Lecture Outline More on MIPS Calling Convention Functions calling functions
More informationCS 316: Procedure Calls/Pipelining
CS 316: Procedure Calls/Pipelining Kavita Bala Fall 2007 Computer Science Cornell University Announcements PA 3 IS out today Lectures on it this Fri and next Tue/Thu Due on the Friday after Fall break
More informationThe remote testing experiment. It works! Code Generation. Lecture 12. Remote testing. From the cs164 newsgroup
The remote testing experiment. It works! Coverage - Score plot 0.9 Code Generation 0.7 0.6 Lecture 12 Coverage 0.5 0.4 0.3 Series1 Poly. (Series1) 0.2 0.1 0 0 10 20 30 40 50 Score CS 164 Lecture 14 Fall
More informationPrinceton 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 informationFunction Calls. Tom Kelliher, CS 220. Oct. 24, SPIM programs due Wednesday. Refer to homework handout for what to turn in, and how.
Function Calls Tom Kelliher, CS 220 Oct. 24, 2011 1 Administrivia Announcements Assignment SPIM programs due Wednesday. Refer to homework handout for what to turn in, and how. From Last Time Outline 1.
More informationSPIM Procedure Calls
SPIM Procedure Calls 22C:60 Jonathan Hall March 29, 2008 1 Motivation We would like to create procedures that are easy to use and easy to read. To this end we will discuss standard conventions as it relates
More informationCSC 8400: Computer Systems. Using the Stack for Function Calls
CSC 84: 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 informationImplementing Subprograms
1 Implementing Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University CS315 Programming Languages Pinar Duygulu The General Semantics of Calls and Returns 2 The subprogram call and return
More informationCode Generation. Lecture 19
Code Generation Lecture 19 Lecture Outline Topic 1: Basic Code Generation The MIPS assembly language A simple source language Stack-machine implementation of the simple language Topic 2: Code Generation
More informationThis Lecture. G53CMP: Lecture 14 Run-Time Organisation I. Example: Lifetime (1) Storage Areas
This Lecture G53CMP: Lecture 14 Run-Time Organisation I Henrik Nilsson University of Nottingham, UK One aspect of run-time organisation: stack-based storage allocation Lifetime and storage Basic stack
More informationG53CMP: Lecture 14. Run-Time Organisation I. Henrik Nilsson. University of Nottingham, UK. G53CMP: Lecture 14 p.1/37
G53CMP: Lecture 14 Run-Time Organisation I Henrik Nilsson University of Nottingham, UK G53CMP: Lecture 14 p.1/37 This Lecture One aspect of run-time organisation: stack-based storage allocation Lifetime
More informationMemory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention
Subroutines Why we use subroutines more modular program (small routines, outside data passed in) more readable, easier to debug code reuse i.e. smaller code space Memory Usage A software convention stack
More informationCode Generation Super Lectures
Code Generation Super Lectures Huge One-Slide Summary Assembly language is untyped, unstructured, low-level and imperative. In a load-store architecture, instructions operate on registers (which are like
More informationThe plot thickens. Some MIPS instructions you can write cannot be translated to a 32-bit number
The plot thickens Some MIPS instructions you can write cannot be translated to a 32-bit number some reasons why 1) constants are too big 2) relative addresses are too big 3) absolute addresses are outside
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 informationIR Generation. May 13, Monday, May 13, 13
IR Generation May 13, 2013 Monday, May 13, 13 Monday, May 13, 13 Monday, May 13, 13 Midterm Results Grades already in Repeal policy Talk to TA by the end of the Tuesday reserve the right to regrade the
More informationEN164: Design of Computing Systems Lecture 11: Processor / ISA 4
EN164: Design of Computing Systems Lecture 11: Processor / ISA 4 Professor Sherief Reda http://scale.engin.brown.edu Electrical Sciences and Computer Engineering School of Engineering Brown University
More informationFunction Calls. 1 Administrivia. Tom Kelliher, CS 240. Feb. 13, Announcements. Collect homework. Assignment. Read
Function Calls Tom Kelliher, CS 240 Feb. 13, 2002 1 Administrivia Announcements Collect homework. Assignment Read 3.7 9. From Last Time SPIM lab. Outline 1. Function calls: stack execution model, memory
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 informationFinal Exam Review Questions
EECS 665 Final Exam Review Questions 1. Give the three-address code (like the quadruples in the csem assignment) that could be emitted to translate the following assignment statement. However, you may
More informationMIPS Assembly (Functions)
ECPE 170 Jeff Shafer University of the Pacific MIPS Assembly (Functions) 2 Lab Schedule This Week Activities Lab work time MIPS functions MIPS Random Number Generator Lab 11 Assignments Due Due by Apr
More informationCS 61C: Great Ideas in Computer Architecture Strings and Func.ons. Anything can be represented as a number, i.e., data or instruc\ons
CS 61C: Great Ideas in Computer Architecture Strings and Func.ons Instructor: Krste Asanovic, Randy H. Katz hdp://inst.eecs.berkeley.edu/~cs61c/sp12 Fall 2012 - - Lecture #7 1 New- School Machine Structures
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 informationThree-Address Code IR
Three-Address Code IR Announcements Programming Project 3 due tonight at 11:59PM. OH today after lecture. Ask questions on Piazzza! Ask questions via email! Programming Project 4 out, due Wednesday, August
More informationCSCI 334: Principles of Programming Languages. Computer Architecture (a really really fast introduction) Lecture 11: Control Structures II
1 byte{ 1 byte{ CSCI 334: Principles of Programming Languages Lecture 11: Control Structures II Computer Architecture (a really really fast introduction) Instructor: Dan Barowy Memory Instructions main
More informationWe defined congruence rules that determine the order of evaluation, using the following evaluation
CS 4110 Programming Languages and Logics Lectures #21: Advanced Types 1 Overview In this lecture we will extend the simply-typed λ-calculus with several features we saw earlier in the course, including
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 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 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 informationType checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39
Type checking Jianguo Lu November 27, 2014 slides adapted from Sean Treichler and Alex Aiken s Jianguo Lu November 27, 2014 1 / 39 Outline 1 Language translation 2 Type checking 3 optimization Jianguo
More informationFunctions in C. Lecture Topics. Lecture materials. Homework. Machine problem. Announcements. ECE 190 Lecture 16 March 9, 2011
Functions in C Lecture Topics Introduction to using functions in C Syntax Examples Memory allocation for variables Lecture materials Textbook 14.1-14.2, 12.5 Homework Machine problem MP3.2 due March 18,
More informationRun-time Environments - 2
Run-time Environments - 2 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture n What is run-time
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 informationCOMP 181. Prelude. Intermediate representations. Today. High-level IR. Types of IRs. Intermediate representations and code generation
Prelude COMP 181 Lecture 14 Intermediate representations and code generation October 19, 2006 Who is Seth Lloyd? Professor of mechanical engineering at MIT, pioneer in quantum computing Article in Nature:
More informationCA Compiler Construction
CA4003 - Compiler Construction David Sinclair When procedure A calls procedure B, we name procedure A the caller and procedure B the callee. A Runtime Environment, also called an Activation Record, is
More informationProgramming Studio #9 ECE 190
Programming Studio #9 ECE 190 Programming Studio #9 Concepts: Functions review 2D Arrays GDB Announcements EXAM 3 CONFLICT REQUESTS, ON COMPASS, DUE THIS MONDAY 5PM. NO EXTENSIONS, NO EXCEPTIONS. Functions
More informationLanguage Techniques for Provably Safe Mobile Code
Language Techniques for Provably Safe Mobile Code Frank Pfenning Carnegie Mellon University Distinguished Lecture Series Computing and Information Sciences Kansas State University October 27, 2000 Acknowledgments:
More informationCS 61C: Great Ideas in Computer Architecture More MIPS, MIPS Functions
CS 61C: Great Ideas in Computer Architecture More MIPS, MIPS Functions Instructors: John Wawrzynek & Vladimir Stojanovic http://inst.eecs.berkeley.edu/~cs61c/fa15 1 Machine Interpretation Levels of Representation/Interpretation
More informationAn Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1
An Overview to Compiler Design 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1 Outline An Overview of Compiler Structure Front End Middle End Back End 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 2 Reading
More informationThe Activation Record (AR)
The Activation Record (AR) [Notes adapted from R. Bodik] Code for function calls and function definitions depends on the layout of the activation record Very simple AR suffices for this language: The result
More informationMIPS Procedure Calls. Lecture 6 CS301
MIPS Procedure Calls Lecture 6 CS301 Function Call Steps Place parameters in accessible location Transfer control to function Acquire storage for procedure variables Perform calculations in function Place
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 informationSystem Software Assignment 1 Runtime Support for Procedures
System Software Assignment 1 Runtime Support for Procedures Exercise 1: Nested procedures Some programming languages like Oberon and Pascal support nested procedures. 1. Find a run-time structure for such
More informationOperational Semantics of Cool
Operational Semantics of Cool Lecture 23 Dr. Sean Peisert ECS 142 Spring 2009 1 Status Project 3 due on Friday Project 4 assigned on Friday. Due June 5, 11:55pm Office Hours this week Fri at 11am No Class
More informationCode Generation. Lecture 31 (courtesy R. Bodik) CS164 Lecture14 Fall2004 1
Code Generation Lecture 31 (courtesy R. Bodik) CS164 Lecture14 Fall2004 1 Lecture Outline Stack machines The MIPS assembly language The x86 assembly language A simple source language Stack-machine implementation
More informationFunctions and the MIPS Calling Convention 2 CS 64: Computer Organization and Design Logic Lecture #11
Functions and the MIPS Calling Convention 2 CS 64: Computer Organization and Design Logic Lecture #11 Ziad Matni Dept. of Computer Science, UCSB Administrative Lab 5 due end of day tomorrow Midterm: to
More informationRun-time Environments
Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction
More informationRun-time Environment
Run-time Environment Prof. James L. Frankel Harvard University Version of 3:08 PM 20-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Storage Organization Automatic objects are
More informationRun-time Environments
Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction
More informationStack-Based Typed Assembly Language
Stack-Based Typed Assembly Language Greg Morrisett Cornell University David Walker Cornell University Karl Crary Carnegie Mellon University Neal Glew Cornell University December 1, 1998 Abstract In previous
More informationOptimization Prof. James L. Frankel Harvard University
Optimization Prof. James L. Frankel Harvard University Version of 4:24 PM 1-May-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reasons to Optimize Reduce execution time Reduce memory
More informationAnnouncements. Scope, Function Calls and Storage Management. Block Structured Languages. Topics. Examples. Simplified Machine Model.
CS 242 2007 Scope, Function Calls and Storage Management John Mitchell Announcements Homework Returned in class Wed; afterwards in 4 th Floor Gates Cabinet SCPD students: attach routing slip, will be returned
More informationReview of Activation Frames. FP of caller Y X Return value A B C
Review of Activation Frames In general, activation frames are organized like this: HI LO Bookkeeping/preserved registers I/O parameters Locals and temps RA of caller FP of caller Y X Return value A B C
More information12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return
Outline Implementing Subprograms In Text: Chapter 10 General semantics of calls and returns Implementing simple subroutines Call Stack Implementing subroutines with stackdynamic local variables Nested
More informationFunction Calling Conventions 2 CS 64: Computer Organization and Design Logic Lecture #10
Function Calling Conventions 2 CS 64: Computer Organization and Design Logic Lecture #10 Ziad Matni Dept. of Computer Science, UCSB Lecture Outline More on MIPS Calling Convention Functions calling functions
More informationProcedure Call and Return Procedure call
Procedures int len(char *s) { for (int l=0; *s!= \0 ; s++) l++; main return l; } void reverse(char *s, char *r) { char *p, *t; int l = len(s); reverse(s,r) N/A *(r+l) = \0 ; reverse l--; for (p=s+l t=r;
More informationSubprograms, Subroutines, and Functions
Subprograms, Subroutines, and Functions Subprograms are also called subroutines, functions, procedures and methods. A function is just a subprogram that returns a value; say Y = SIN(X). In general, the
More informationMIPS Functions and Instruction Formats
MIPS Functions and Instruction Formats 1 The Contract: The MIPS Calling Convention You write functions, your compiler writes functions, other compilers write functions And all your functions call other
More informationProgramming Languages: Lecture 12
1 Programming Languages: Lecture 12 Chapter 10: Implementing Subprograms Jinwoo Kim jwkim@jjay.cuny.edu Chapter 10 Topics 2 The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing
More informationCS 2210 Programming Project (Part IV)
CS 2210 Programming Project (Part IV) April 25, 2018 Code Generation This project is intended to give you experience in writing a code generator as well as bring together the various issues of code generation
More informationCOL728 Minor2 Exam Compiler Design Sem II, Answer all 5 questions Max. Marks: 20
COL728 Minor2 Exam Compiler Design Sem II, 2017-18 Answer all 5 questions Max. Marks: 20 1. Short questions a. Give an example of a program that is not a legal program if we assume static scoping, but
More informationComp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation
Comp 204: Computer Systems and Their Implementation Lecture 22: Code Generation and Optimisation 1 Today Code generation Three address code Code optimisation Techniques Classification of optimisations
More informationStacks and Frames Demystified. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han
s and Frames Demystified CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han Announcements Homework Set #2 due Friday at 11 am - extension Program Assignment #1 due Tuesday Feb. 15 at 11 am - note extension
More informationMidterm II CS164, Spring 2006
Midterm II CS164, Spring 2006 April 11, 2006 Please read all instructions (including these) carefully. Write your name, login, SID, and circle the section time. There are 10 pages in this exam and 4 questions,
More informationMIPS Assembly (FuncDons)
ECPE 170 Jeff Shafer University of the Pacific MIPS Assembly (FuncDons) Instructor: Dr. Vivek Pallipuram 2 Lab Schedule This Week AcDviDes Lab work Dme MIPS funcdons MIPS Random Number Generator Lab 10
More informationCS 110 Computer Architecture Lecture 6: More MIPS, MIPS Functions
CS 110 Computer Architecture Lecture 6: More MIPS, MIPS Functions Instructor: Sören Schwertfeger http://shtech.org/courses/ca/ School of Information Science and Technology SIST ShanghaiTech University
More information