Run-time environments

Size: px
Start display at page:

Download "Run-time environments"

Transcription

1 Status Genetion Goals and Considetions sis okens eliminates illegal tokens rees eliminates ill-formed parse trees tic analysis ecoted tree with additional information attached eliminates remaining static errors dynamic back-end phases: = we are here tion (at various semantic levels) ion : execution of geneted code must be consistent with s specified dynamic semantics however, these semantics do not completely specify ben to allow compiler to accomplish other goals, such as uce code that executes as quickly as possible, or reliably in timing constints (as in real-time systems) ze size of geneted progm or of runtime data strucize optimization can be conflicting goals Why? speed: especially during development or when using JITs cations in code genetion come from trying to be fast rrect, because this requires attention to special cases 2: CS164: Lecture # : CS164: Lecture #25 4 5: Introduction to Runtime Organization Run-time environments ng code genetion, we need to understand what we are ate e term virtual machine to refer to the compiler s target a bare hardware architecture(small embedded systems) terpreter, as for Java, or an interpreter that does adpilation at execution, as in modern Java JITs a machine whose machine language is another progme such as C, Java, or Javascript ll stick to hardware + conventions for using it (the API: rogmmer s interface) + some runtime-support libry 2: CS164: Lecture # : CS164: Lecture #25 3

2 tivations and Lifetimes (Extents) Activation Records of procedure P is an activation of P of an activation of P is all the steps to execute P, he steps in procedures P calls (extent) of a variable is the portion of execution durt variable exists (whether or not the code currently n reference it) dynamic (run-time) concept, as opposed to scope, which procedure activations and local variables properly nest read), suggesting a stack data structure for maintainime state les have extents that are not coordinated with procereturns tion needed to manage one procedure activation is called n record (AR) or (stack) fme e F (the caller) calls G (the callee), typically G s activacontains a mix of data about F and G: ddress to instructions in F ink to the AR for F save registers needed by F r G s local variables ion needed to find non-local variables needed by G ry space for intermediate results, arguments to and rees from functions that G calls machine status needed to restore F s context (signal oating-point unit pameters) n architecture and compiler, registers typically hold part mes), especially pameters, return values,, and the current stack top and fme 2: CS164: Lecture # : CS164: Lecture #25 8 Subgoals and Constints improving speed and size: nstruction counts structure static, known at compilation (eg, known conets to fields) Contst Java and Python use of registers ( top of the memory hierchy ) improving compilation speed: p analyses as local as possible (single statement, block, ), because their compilation-time cost tends to be nonssumptions about control flow: procedure calls always atements genelly execute in sequence (Where are ted?) Memory Layout of procedure activations and variables give rise to the l data layout for a (single-threaded) progm: Execution stack ( stack segment ) Dynamic data ( heap ) Static data ( data segment(s) ) Highest memory address 2: CS164: Lecture #25 5 Instructions ( text segment(s) ) Lowest memory address 22: CS164: Lecture #25 7

3 Static Stoge hieving Runtime Effects Functions stoge refers to variables whose extent is an entire d whose size is typically fixed before execution y stored in an activation record, but assigned a fixed iables with file scope (declared static in C) and with age ( global ) are in static stoge variables are an odd case: they don t really fit this ) sign and runtime design intect Semantics of funcood example nction features: recursion, no nesting, fixed-sized data with size known er rsion ble-sized unboxed data ting of functions, up-level addressing ction values w/ properly nested accesses only el closures tinuations ween these effects and structure of machines: anguages typically only make it easy to access things at s like R +C, where R is an address in a register and C vely small integer constant e, fixed offsets good, data-dependent offsets bad 2: CS164: Lecture # : CS164: Lecture #25 12 Calling Conventions ns are possible: nge order of fme elements caller/callee responsibilities differently to use an ary-like implementation of the stack: can d list of ARs ion is better if it improves execution speed or simplifies ion must determine, at compile-time, the layout of activaand genete code that correctly accesses locations in n record, it is common to compile procedures sepately and ss of each other s details, which motivates the impong conventions Heap Stoge hose extent is greater than that of the AR in which they can t be kept there: ) { return new Bar(); } oge dynamically allocated ocated out of an area called the heap (confusingly, not the heap used for priority qeues!) 2: CS164: Lecture # : CS164: Lecture #25 11

4 1: Calling conventions ng Sequence when Fme Size is Fixed se function inlining, will need to save return address, ny options Here s one example, from the IBM 360, of on F from G and passing values 3 and 4: F Reserve 2 4-byte words of static stoge */ G R1,GArgs Load Address of arguments into register 1 R0,3 Store 3 and 4 in GArgs+0 and GArgs+4 R0,GArgs R0,4 R0,GArgs+4 R14,F Call ("Bnch and Link") to F, R14 gets return point ontain F F R14,FRet Save return address R2,0(R1) Load first argument nks not really needed lls g calls f, as at right the initial code of g (its crements the stack pointer f g s activation record (its epilogue): s the stack pointer by this he return address, and to address just popped arguments to f g s arguments to g fixed distance Base of 1st fme R14,FRet Get return address R14 Bnch to it 2: CS164: Lecture # : CS164: Lecture #25 16 ecursion, no nesting, fixed-sized data 2: Add recursion of data is bounded, and there is only one instantiation at a time es, return addresses, and return values can go in fixed ded at all d FORTRAN progms in the early days ispense with call instructions altogether: expand funcine Eg, = becomes = x_1 = 3 x_1 *= 42 y_1 = 9 + x_1 g (x_1, y_1) gm may get bigger than you want Typically, one inll, frequently executed functions amount of data is und sevel instantiations of n be active simultaneously e kind of expandable data stack riable sizes still fixed, so activation record (stack ed iable addresses and the mic link are known offsets ointer, which is typically in shows the conventions we a32, where we ll define a as starting after the re- ) arguments to f g s arguments to g fixed distance Base of 1st fme 2: CS164: Lecture # : CS164: Lecture #25 15

5 Add Variable-Sized Unboxed Data 3: Calling sequence for the ia32 ans not on heap all quantities on stack to e ementations have fixedmes st heap allocation, so s also provide for placing data directly on stack ion on the stack ) g ed dynamic link () insure fixed offsets of ame base (fme pointer) lls g, which has variableary (see right) unboxed stoge other local pointer arguments to g Fme pointer Assembly excerpt (GNU opend order): f: / Return address (RA) at SP, x at SP+4, y at SP+8 pushl %ebp / PRO: Save old dynamic link movl %esp, %ebp / PRO: Set ebp to current fme base subl $4, %esp / PRO: Decrement SP to make space for s movl $1, -4(%ebp) / s = 1 L2: cmpl $0, 12(%ebp) / compare 0 with y (now at BP+12) jle L3 movl -4(%ebp), %eax / tmp = s imull 8(%ebp), %eax / tmp *= x movl %eax, -4(%ebp) / s = tmp leal 12(%ebp), %eax / tmp = &y decl (%eax) / *tmp -= 1 jmp L2 L3: movl -4(%ebp), %eax / return s leave / EPI: Restore %esp to %ebp+4, %ebp to 0(%ebp), ret / EPI: and then pop RA and return g: movl $5, 4(%esp) / Put q and 5 on stack (q on top) movl 8(%ebp), %eax / tmp = q movl %eax, (%esp) / top of stack = q call f / bnch to f and push address of next next: 2: CS164: Lecture # : CS164: Lecture # : Calling sequence from ia32 Other Uses of the Dynamic Link { ; Assembly excerpt (GNU opend order): / PRO = Prologue, EPI = Epilogue f: / Return address (RA) at SP, x at SP+4, y at SP+8 subl $4, %esp / PRO: Decrement SP to make space for s movl $1, (%esp) / s = 1 L2: cmpl $0, 12(%esp) / compare 0 with y (now at SP+12) jle L3 movl (%esp), %eax / tmp = s imull 8(%esp), %eax / tmp *= x movl %eax, (%esp) / s = tmp leal 12(%esp), %eax / tmp = &y decl (%eax) / *tmp -= 1 jmp L2 L3: movl (%esp), %eax / return s in EAX addl $4, %esp / EPI: Restore stack pointer so RA on top, ret / EPI: then pop RA and return g: movl $5, 4(%esp) / Put q and 5 on stack (q on top) movl 12(%esp), %eax / tmp = q movl %eax, (%esp) / top of stack = q call f / bnch to f and push address of next next: ynamic link even when size of AR is fixed f same sttegy for all ARs, simplifies code genetion sier to write genel functions that unwind the stack s off, thus returning) 2: CS164: Lecture # : CS164: Lecture #25 19

6 this problem, go nment diagms! had a pointer to sing environment xample from last fme contains a e f fme where efined: the static cal variable, use ointer (or maybe ) bal, use absolute al of nesting functatic link once per levels of nesting Static Links g s fme g s fme g s fme fme Calling sequence for the ia32: f1 eturn s; } 1) { + n1 s + g1 (); s) + f1 (n0) (); to f1 points to: y of n1 tic link f0 s fme */ f1: / Static link to f0 s fme is in %ecx pushl %ebp / PRO movl %esp, %ebp / PRO pushl %esi / PRO: Save %esi pushl %ebx / PRO: Save %ebx subl $32, %esp / PRO movl %ecx, %ebx / Save link to f0 s fme movl 8(%ebp), %eax / Move n1 movl %eax, -16(%ebp) / to new local movl %ebx, -12(%ebp) / Save static link to f0 in local movl 4(%ebx), %edx / Fetch s from f0 s fme movl %edx, (%esp) / And pass to f2 leal -16(%ebp), %ecx / Pass static link to my fme to f2 call f2 movl %eax, %esi / Save f2(s) movl (%ebx), %eax / Fetch n0 from f0 s fme movl %eax, (%esp) / and pass to f1 movl %ebx, %ecx / Also pass on my static link call f1 addl %eax, %esi / Compute f2(s) + f1(n0) movl %ebx, %ecx / Pass same static link to g1 call g1 leal (%esi,%eax), %eax / Compute f2(s)+f1(n0)+g1() addl $32, %esp / EPI popl %ebx / EPI: restore %ebx popl %esi / EPI: restored %esi popl %ebp / EPI ret / EPI 2: CS164: Lecture # : CS164: Lecture #25 24 esting of Functions, Up-Level Addressing Calling sequence for the ia32: f0 ns can be nested, there ses of variable: nction closing function or (c) is easy It s (b) ting ython): Local to f q): 0: return q+y eturn g (n-1, q*2) e any distance away from g s fme g s fme g s fme fme How far??? Enclosing f eturn s; } 1) { + n1 s + g1 (); s) + f1 (n0) (); Assembly excerpt for f0: f0: / Does not need to be passed a static link pushl %ebp / PRO movl %esp, %ebp / PRO subl $40, %esp / PRO movl 8(%ebp), %eax / Fetch n0 movl %eax, -16(%ebp) / Move n0 to new local variable movl -16(%ebp), %eax / Negate n0 negl %eax movl %eax, -12(%ebp) / and store in s leal -16(%ebp), %eax / Compute static link to f0 s fme movl $10, (%esp) / Pass argument 10 movl %eax, %ecx / and static link call f1 / to f1 leave / EPI ret / EPI / Static link into f0 s fme points to: / int n0 / Copy of n0 / int s 2: CS164: Lecture # : CS164: Lecture #25 23

7 alling sequence for the ia32: f2 Using the global display (sketch) turn s; } ) { + n1 + g1 (); ) + f1 (n0) (); Assembly excerpt for f2: f2: / Static link (into f1 s fme) in %ecx pushl %ebp / PRO movl %esp, %ebp / PRO pushl %ebx / PRO: Save %ebx movl %ecx, %eax / Fetch static link to f0 movl 4(%eax), %edx / from f1 s fme movl (%edx), %ecx / to get n0 from f0 s fme movl (%eax), %edx / Fetch n1 from f1 s fme addl %edx, %ecx / Add n0 + n1 movl 4(%eax), %edx / Fetch static link to f0 again movl 4(%edx), %edx / Fetch s from f0 s fme leal (%ecx,%edx), %ebx / And add to n0 + n1 movl 4(%eax), %eax / Fetch static link to f0 movl %eax, %ecx / and pass to g1 call g1 leal (%ebx,%eax), %eax / Add g1() to n0 + n1 + s popl %ebx / EPI: Restore %ebx popl %ebp / EPI ret / EPI eturn s; } 1) { + n1 s + g1 (); s) + f1 (n0) (); f0: movl _DISPLAY+0,%eax / PRO: Save old _DISPLAY[0] movl %eax,-12(%ebp) / PRO: somewhere movl %ebp,_display+0 / PRO: Put my %ebp in _DISPLAY[0] movl -12(%ebp),%ecx / EPI: Restore old _DISPLAY[0] movl %ecx,_display+0 / EPI f1: movl _DISPLAY+4,%eax / PRO: Save old _DISPLAY[1] movl %eax,-12(%ebp) / PRO: somewhere movl %ebp,_display+4 / PRO: Put my %ebp in _DISPLAY[1] likewise for epilogue f2 and g1: no ext code, since they have no nested functions 2: CS164: Lecture # : CS164: Lecture #25 28 alling sequence for the ia32: g1 The Global Display turn s; } ) { + n1 + g1 (); ) + f1 (n0) (); Assembly excerpt for g1: g1: / Static link (to f0 s fme) in %ecx pushl %ebp / PRO movl %esp, %ebp / PRO movl %ecx, %eax / Fetch s from movl 4(%eax), %eax / f0 s fme popl %ebp / EPI ret / EPI first solution to nested function d an ary indexed by call level, static links 1 () : (): g2 () (): g2 () g1 () () f1 () : f1 () enter a function at lexical level k nside k functions), save pointer to e in DISPLAY[k]; restore on exit able at lexical level k through g1 s fme g2 s fme g2 s fme f2 s fme f1 s fme f1 s fme g1 s fme g2 2 g1 1 f0 0 ly on scope rules and proper nesting f0 s fme DISPLAY 2: CS164: Lecture # : CS164: Lecture #25 27

8 Function Value Representation Representing Closures ): (y): f2 (z): turn x + y + z t h1 (f2) (g): g (3) ) om the main progm; e stack when f2 finally see right) s value (as a function) ed, current fme is That is stored in the ed to h1 static links; global disique does not fare as ] f2 s fme h1 s fme f1 s fme f0 s fme Value of g (ie, f2) code for f2 st forbid this case (as guages do): 68 would not allow r to f (last slide) to be ed from incr e could allow it, and do hing ndom when f (ie ta) is called and Python allow it and ght thing t in genel put local (and a static link) in a n the heap, instead of ack temp stoge etc delta, & n Value of incr(2) code for f 2: CS164: Lecture # : CS164: Lecture #25 32 unction Values, Properly Nested Access function nesting al variables are global, and have fixed addresses esent a variable whose value is a function, need only to ress of the function s code sted functions possible, function value must contain n is finally called, must be told what its static link is that access is properly nested: variables accessed only e of their fme sent function with address of code + the address of at contains that function s definition ent diagms again!! 6: Genel Closures ppens when the fme unction value points to y? ed the previous repre- (#5), we d get a danter in this case: ncr (n): lta = n f f (x): return delta + x turn f incr(2) p2(3) incr s fme with delta During execution of incr(2) Value of incr(2) code for f 2: CS164: Lecture # : CS164: Lecture #25 31

9 Representing Closures Could just forbid this case (as some languages do): Algol 68 would not allow pointer to f (last slide) to be returned from incr Or, one could allow it, and do something ndom when f (ie via delta) is called Scheme and Python allow it and do the right thing But must in genel put local variables (and a static link) in a record on the heap, instead of on the stack Now fme can disappear harmlessly delta, & n Value of incr(2) code for f Last modified: Fri Mar 30 13:22: CS164: Lecture #25 32

10 Summary roblem Solution ecursion, no nestzed data with size static variables to hold return Use inline expansion or use mpiler, first-class addresses,, etc es on Need stack variable-sized un- Need to keep both stack pointer and fme pointer lass function values Add static link or global display ctions, up-level ad- on values w/ propccesses: functions tain their link (Global display Static link, function values con- meters only doesn t work so well) al closures: firstons returned from link on heap Store local variables and static stored in variables ations Put everything on the heap 2: CS164: Lecture # : Continuations tion return were not the end? ): return cont c : "a", x, n, ll_with_continuation (f) "b", x, n, -1); print "c", x, n, 1; print; c() # Prints: # a 1 0 b 1 0 c 1 1 c 1 2 # b 2 0 c 2 1 c 2 2 # b 3 0 c 3 1 c 3 2 tion, c, passed to f is the function that does whatever o happen after I return from f o implement exceptions, threads, co-routines ion? Nothingmuchforitbuttoputallactivationfmes ost can do better on special cases like exceptions 2: CS164: Lecture #25 33

Lecture #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: 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 information

Status. Lecture #15: Introduction to Runtime Organization. Run-time environments. Code Generation Goals and Considerations

Status. 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 information

Assembly Language: Function Calls" Goals of this Lecture"

Assembly 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 information

Assembly Language: Function Calls

Assembly 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 information

Assembly Language: Function Calls" Goals of this Lecture"

Assembly 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 information

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

Assembly 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 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 IA-32 (1) Characteristics Region of memory managed with stack discipline

More information

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

Procedure 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 information

CS213. Machine-Level Programming III: Procedures

CS213. 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 information

Assembly III: Procedures. Jo, Heeseung

Assembly 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 information

ASSEMBLY III: PROCEDURES. Jo, Heeseung

ASSEMBLY 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 information

THEORY OF COMPILATION

THEORY 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 information

CIT Week13 Lecture

CIT 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 information

CS 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 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 information

Machine-level Programming (3)

Machine-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 information

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

Procedure 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 information

The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002

The 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 information

Function 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) 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 information

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110

Question 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 information

CPSC W Term 2 Problem Set #3 - Solution

CPSC 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 information

What is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation

What 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

4) C = 96 * B 5) 1 and 3 only 6) 2 and 4 only

4) 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 information

COMP 210 Example Question Exam 2 (Solutions at the bottom)

COMP 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 information

CS61 Section Solutions 3

CS61 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 information

CPEG421/621 Tutorial

CPEG421/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 information

Compiler Construction D7011E

Compiler 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 information

Machine-Level Programming III: Procedures

Machine-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 information

Register Allocation, iii. Bringing in functions & using spilling & coalescing

Register 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 information

X86 Assembly -Procedure II:1

X86 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 information

Compilation /15a Lecture 7. Activation Records Noam Rinetzky

Compilation /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 information

Process Layout and Function Calls

Process Layout and Function Calls Process Layout and Function Calls CS 6 Spring 07 / 8 Process Layout in Memory Stack grows towards decreasing addresses. is initialized at run-time. Heap grow towards increasing addresses. is initialized

More information

CAS CS Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm

CAS 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 information

W4118: PC Hardware and x86. Junfeng Yang

W4118: 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 information

CS 33: Week 3 Discussion. x86 Assembly (v1.0) Section 1G

CS 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 information

CS241 Computer Organization Spring 2015 IA

CS241 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 information

Assignment 11: functions, calling conventions, and the stack

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 information

CSC 2400: Computing Systems. X86 Assembly: Function Calls"

CSC 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 information

Instruction Set Architecture

Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant adapted by Jason Fritts http://csapp.cs.cmu.edu CS:APP2e Hardware Architecture - using Y86 ISA For learning aspects

More information

Region of memory managed with stack discipline Grows toward lower addresses. Register %esp contains lowest stack address = address of top element

Region of memory managed with stack discipline Grows toward lower addresses. Register %esp contains lowest stack address = address of top element Machine Representa/on of Programs: Procedures Instructors: Sanjeev Se(a 1 IA32 Stack Region of memory managed with stack discipline Grows toward lower addresses Stack BoGom Increasing Addresses Register

More information

Systems I. Machine-Level Programming V: Procedures

Systems 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 information

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86 Lecture 15 Intel Manual, Vol. 1, Chapter 3 Hampden-Sydney College Fri, Mar 6, 2009 Outline 1 2 Overview See the reference IA-32 Intel Software Developer s Manual Volume 1: Basic, Chapter 3. Instructions

More information

Intel assembly language using gcc

Intel 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 information

X86 Stack Calling Function POV

X86 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 information

The x86 Architecture

The x86 Architecture The x86 Architecture Lecture 24 Intel Manual, Vol. 1, Chapter 3 Robb T. Koether Hampden-Sydney College Fri, Mar 20, 2015 Robb T. Koether (Hampden-Sydney College) The x86 Architecture Fri, Mar 20, 2015

More information

211: Computer Architecture Summer 2016

211: Computer Architecture Summer 2016 211: Computer Architecture Summer 2016 Liu Liu Topic: Assembly Programming Storage - Assembly Programming: Recap - project2 - Structure/ Array Representation - Structure Alignment Rutgers University Liu

More information

Instruction Set Architecture

Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant Carnegie Mellon University http://csapp.cs.cmu.edu CS:APP Instruction Set Architecture Assembly Language View! Processor

More information

administrivia 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? 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 information

Instruction Set Architecture

Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant Carnegie Mellon University http://csapp.cs.cmu.edu CS:APP Instruction Set Architecture Assembly Language View Processor

More information

Winter Compiler Construction T11 Activation records + Introduction to x86 assembly. Today. Tips for PA4. Today:

Winter Compiler Construction T11 Activation records + Introduction to x86 assembly. Today. Tips for PA4. Today: Winter 2006-2007 Compiler Construction T11 Activation records + Introduction to x86 assembly Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University Today ic IC Language Lexical Analysis

More information

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions

AS08-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 information

Sungkyunkwan University

Sungkyunkwan 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 information

x86 assembly CS449 Fall 2017

x86 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 information

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.

What 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 information

Giving credit where credit is due

Giving 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 information

Subprograms: Local Variables

Subprograms: Local Variables Subprograms: Local Variables ICS312 Machine-Level and Systems Programming Henri Casanova (henric@hawaii.edu) Local Variables in Subprograms In all the examples we have seen so far, the subprograms were

More information

The Activation Record (AR)

The 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 information

You may work with a partner on this quiz; both of you must submit your answers.

You 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 information

IA32 Stack. Lecture 5 Machine-Level Programming III: Procedures. IA32 Stack Popping. IA32 Stack Pushing. Topics. Pushing. Popping

IA32 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 information

Implementing 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. 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 information

Code Generation. Lecture 30

Code 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 information

ECE 391 Exam 1 Review Session - Spring Brought to you by HKN

ECE 391 Exam 1 Review Session - Spring Brought to you by HKN ECE 391 Exam 1 Review Session - Spring 2018 Brought to you by HKN DISCLAIMER There is A LOT (like a LOT) of information that can be tested for on the exam, and by the nature of the course you never really

More information

Instructor: Alvin R. Lebeck

Instructor: 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 information

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18 Access Young W. Lim 2017-01-27 Fri Young W. Lim Access 2017-01-27 Fri 1 / 18 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Young W. Lim Access 2017-01-27 Fri 2 / 18 Based

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Warren Hunt, Jr. and Bill Young Department of Computer Sciences University of Texas at Austin Last updated: October 1, 2014 at 12:03 CS429 Slideset 6: 1 Topics

More information

Machine-Level Programming II: Control and Arithmetic

Machine-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 information

Instruction Set Architecture

Instruction Set Architecture CISC 360 Instruction Set Architecture Michela Taufer October 9, 2008 Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective, R. Bryant and D. O'Hallaron, Prentice Hall, 2003 Chapter

More information

CISC 360 Instruction Set Architecture

CISC 360 Instruction Set Architecture CISC 360 Instruction Set Architecture Michela Taufer October 9, 2008 Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective, R. Bryant and D. O'Hallaron, Prentice Hall, 2003 Chapter

More information

Lab 10: Introduction to x86 Assembly

Lab 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 information

CSC 2400: Computing Systems. X86 Assembly: Function Calls

CSC 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 information

Stack Discipline Jan. 19, 2018

Stack Discipline Jan. 19, 2018 15-410 An Experience Like No Other Discipline Jan. 19, 2018 Dave Eckhardt Brian Railing Slides originally stolen from 15-213 1 15-410, S 18 Synchronization Registration The wait list will probably be done

More information

Process Layout, Function Calls, and the Heap

Process Layout, Function Calls, and the Heap Process Layout, Function Calls, and the Heap CS 6 Spring 20 Prof. Vern Paxson TAs: Devdatta Akhawe, Mobin Javed, Matthias Vallentin January 9, 20 / 5 2 / 5 Outline Process Layout Function Calls The Heap

More information

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang

CMSC 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 information

An Elegant Weapon for a More Civilized Age

An 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 information

IA32 Stack The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, IA32 Stack Popping. IA32 Stack Pushing

IA32 Stack The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, IA32 Stack Popping. IA32 Stack Pushing 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 IA32 Region

More information

x86 architecture et similia

x86 architecture et similia x86 architecture et similia 1 FREELY INSPIRED FROM CLASS 6.828, MIT A full PC has: PC architecture 2 an x86 CPU with registers, execution unit, and memory management CPU chip pins include address and data

More information

1 /* 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 */ 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 information

Stacks and Frames Demystified. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Stacks 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 information

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

EECE.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 information

An Experience Like No Other. Stack Discipline Aug. 30, 2006

An Experience Like No Other. Stack Discipline Aug. 30, 2006 15-410 An Experience Like No Other Discipline Aug. 30, 2006 Bruce Maggs Dave Eckhardt Slides originally stolen from 15-213 15-410, F 06 Synchronization Registration If you're here but not registered, please

More information

Machine Programming 3: Procedures

Machine Programming 3: Procedures Machine Programming 3: Procedures CS61, Lecture 5 Prof. Stephen Chong September 15, 2011 Announcements Assignment 2 (Binary bomb) due next week If you haven t yet please create a VM to make sure the infrastructure

More information

System Programming and Computer Architecture (Fall 2009)

System 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 information

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

Run-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 information

Run-time Environments

Run-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 information

Practical Malware Analysis

Practical Malware Analysis Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the

More information

Run-time Environments

Run-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 information

X86 Review Process Layout, ISA, etc. CS642: Computer Security. Drew Davidson

X86 Review Process Layout, ISA, etc. CS642: Computer Security. Drew Davidson X86 Review Process Layout, ISA, etc. CS642: Computer Security Drew Davidson davidson@cs.wisc.edu From Last Time ACL-based permissions (UNIX style) Read, Write, execute can be restricted on users and groups

More information

Lecture Outline. Code Generation. Lecture 30. Example of a Stack Machine Program. Stack Machines

Lecture 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 information

Assembly I: Basic Operations. Jo, Heeseung

Assembly I: Basic Operations. Jo, Heeseung Assembly I: Basic Operations Jo, Heeseung Moving Data (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C

More information

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19 Access Young W. Lim 2017-06-10 Sat Young W. Lim Access 2017-06-10 Sat 1 / 19 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Data Movement Examples Young W. Lim Access 2017-06-10

More information

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung ASSEMBLY I: BASIC OPERATIONS Jo, Heeseung MOVING DATA (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C

More information

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View Computer Architecture I Instruction Set Architecture Assembly Language View Processor state Registers, memory, Instructions addl, movl, andl, How instructions are encoded as bytes Layer of Abstraction

More information

CS 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 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 information

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 21: Generating Pentium Code 10 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Simple Code Generation Three-address code makes it

More information

Chapter 4 Processor Architecture: Y86 (Sections 4.1 & 4.3) with material from Dr. Bin Ren, College of William & Mary

Chapter 4 Processor Architecture: Y86 (Sections 4.1 & 4.3) with material from Dr. Bin Ren, College of William & Mary Chapter 4 Processor Architecture: Y86 (Sections 4.1 & 4.3) with material from Dr. Bin Ren, College of William & Mary 1 Outline Introduction to assembly programing Introduction to Y86 Y86 instructions,

More information

CSE 351: Week 4. Tom Bergan, TA

CSE 351: Week 4. Tom Bergan, TA CSE 35 Week 4 Tom Bergan, TA Does this code look okay? int binarysearch(int a[], int length, int key) { int low = 0; int high = length - ; while (low

More information

Homework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1

Homework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1 Homework In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, 361-367 Practice Exam 1 1 In-line Assembly Code The gcc compiler allows you to put assembly instructions in-line

More information

CS241 Computer Organization Spring Loops & Arrays

CS241 Computer Organization Spring Loops & Arrays CS241 Computer Organization Spring 2015 Loops & Arrays 2-26 2015 Outline! Loops C loops: while, for, do-while Translation to jump to middle! Arrays Read: CS:APP2 Chapter 3, sections 3.6 3.7 IA32 Overview

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

Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call

Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call Call without Parameter Value Transfer What are involved? ESP Stack Pointer Register Grows by 4 for EIP (return address) storage Stack -- Memory which holds register contents Will keep the EIP of the next

More information

Object-oriented features

Object-oriented features Chapter 1 Object-oriented features The compiler s job for a procedural language like C is relatively straightforward, because C and most other compiled procedural languages have been designed to approximate

More information