University of Washington

Size: px
Start display at page:

Download "University of Washington"

Transcription

1 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 Java: Car c = new Car(); c.setmiles(100); c.setgals(17); float mpg = c.getmpg(); OS: Memory & data Integers & floats Machine code & C x86 assembly Procedures & stacks Arrays & structs Memory & caches Processes Virtual memory Memory allocation Java vs. C Section 5: Procedures & s s in memory and stack operations The stack used to keep track of procedure calls Return addresses and urn values -based languages The Linux stack frame Passing arguments on the stack Allocating local variables on the stack Register-saving conventions Procedures and stacks on x64 architecture Procedures and s Memory Layout Memory Layout 2 N -1 local variables; procedure context writable; not executable Managed automatically (by compiler) Dynamic Data (Heap) variables allocated with new or malloc writable; not executable Dynamic Data (Heap) Managed by programmer Static Data static variables (including global variables (C)) writable; not executable Static Data Initialized when process starts Literals literals (e.g., example ) Read-only; not executable Literals Initialized when process starts 0 Instructions Read-only; executable Instructions Initialized when process starts Procedures and s Procedures and s

2 IA32 Call IA32 Call : Push Region of memory managed with a stack discipline Grows toward lower addresses Customarily shown upside-down Bottom Increasing Addresses pushl Src Bottom Increasing Addresses Register contains lowest stack address = address of top element Pointer: Grows Down Pointer: Grows Down Top Top Procedures and s Procedures and s IA32 Call : Push IA32 Call : Pop pushl Src Fetch value from Src Decrement by 4 (why 4?) Store value at address given by Bottom Increasing Addresses popl Dest Bottom Increasing Addresses Pointer: -4 Grows Down Pointer: Grows Down Top Top Procedures and s Procedures and s

3 IA32 Call : Pop popl Dest Load value from address Write value to Dest Increment by 4 Item still remains, we are just not referencing it any more Not really moving out of memory Pointer: Bottom +4 Increasing Addresses Grows Down Section 5: Procedures & s s in memory and stack operations The stack used to keep track of procedure calls Return addresses and urn values -based languages The Linux stack frame Passing arguments on the stack Allocating local variables on the stack Register-saving conventions Procedures and stacks on x64 architecture Top Procedures and s Procedure Call Overview Caller <set up args> call <clean up args> <find urn val> Calleemust know where to find args Callee <create local vars> <set up urn val> <destroy local vars> urn Callee must know where to find urn address Caller must know where to find urn val Caller and Calleerun on same CPU use the same registers Caller might need to save registers that Callee might use Callee might need to save registers that Caller has used Procedure Call Overview Caller <save regs> <set up args> call <clean up args> <restore regs> <find urn val> Callee <save regs> <create local vars> <set up urn val> <destroy local vars> <restore regs> urn The conventionof where to leave/find things is called the procedure call linkage Details vary between systems We will see the convention for IA32/Linux in detail What could happen if our program didn t follow these conventions?

4 Procedure Control Flow Use stack to support procedure call and urn Procedure call: call label Push urn address on stack Jump to label Procedure Control Flow Use stack to support procedure call and urn Procedure call: call label Push urn address on stack Jump to label Return address: Address of instruction after call from disassembly: e: e8 3d call 8048b90 <main> : 50 pushl %eax Return address = Procedure urn: Pop urn address from stack Jump to address Procedure Call e: e8 3d call 8048b90 <main> : 50 pushl %eax call 8048b90 Procedure Call e: e8 3d call 8048b90 <main> : 50 pushl %eax call 8048b90 %eip 0x804854e %eip 0x804854e %eip 0x804854e %eip: program counter %eip: program counter

5 Procedure Call e: e8 3d call 8048b90 <main> : 50 pushl %eax call 8048b90 Procedure Call e: e8 3d call 8048b90 <main> : 50 pushl %eax call 8048b90 %eip 0x804854e %eip 0x804854e %eip 0x804854e %eip 0x804854e %eip: program counter %eip: program counter Procedure Call e: e8 3d call 8048b90 <main> : 50 pushl %eax Procedure Return : c3 call 8048b90 %eip 0x804854e %eip + 0x000063d %eip 0x %eip: program counter 0x8048b90 %eip: program counter

6 Procedure Return : c3 Procedure Return : c3 %eip 0x %eip 0x %eip 0x %eip 0x %eip: program counter %eip: program counter Procedure Return : c3 %eip 0x %eip 0x Return Values By convention, values urned by procedures are placed in the %eax register Choice of %eax is arbitrary, could have easily been a different register Caller must make sure to save that register before calling a callee that urns a value Part of register-saving convention we ll see later Calleeplaced urn value (any te that can fit in 4 bytes integer, float, pointer, etc.) into the %eax register For urn values greater than 4 bytes, best to urn a pointer to them Upon urn, caller finds the urn value in the %eaxregister %eip: program counter

7 Section 5: Procedures & s s in memory and stack operations The stack used to keep track of procedure calls Return addresses and urn values -based languages The Linux stack frame Passing arguments on the stack Allocating local variables on the stack Register-saving conventions Procedures and stacks on x64 architecture Languages that support recursion e.g., C, Pascal, Java Code must bere-entrant Multiple simultaneous instantiations of single procedure Need some place to store state of each instantiation Arguments Local variables Return pointer discipline State for a given procedure needed for a limited time Starting from when it is called to when it urns Callee always urns before caller does allocated inframes State for a single procedure instantiation Call Chain ( ) (); ( ) (); (); ( ) (); Procedure is recursive (calls itself) Call Chain Frames Contents Local variables Function arguments Return information Temporary space Frame Pointer: Pointer: Management Space allocated when procedure is entered Set-up code Space deallocated upon urn Finish code Previous Frame Frame for current proc Top

8 ( ) (); ( ) (); (); ( ) (); ( ) ();

9 ( ) (); ( ) (); ( ) (); ( ) (); ();

10 ( ) ( ) (); (); Section 5: Procedures & s ( ) (); s in memory and stack operations The stack used to keep track of procedure calls Return addresses and urn values -based languages The Linux stack frame Passing arguments on the stack Allocating local variables on the stack Register-saving conventions Procedures and stacks on x64 architecture

11 IA32/ Revisiting swap Current Frame ( Top to Bottom) Argument build area (parameters for function about to be called) Local variables (if can t be kept in registers) Saved register context (when reusing registers) Old frame pointer (for caller) Caller s Frame Return address Pushed by call instruction Arguments for this call Frame pointer pointer Caller Frame Arguments Return Addr Old Saved Registers + Local Variables Argument Build int zip1 = 15213; int zip2 = 98195; void call_swap() swap(&zip1, &zip2); void swap(int *, int *) int t0 = *; int t1 = *; * = t1; * = t0; Revisiting swap int zip1 = 15213; int zip2 = 98195; void call_swap() swap(&zip1, &zip2); Calling swap from call_swap call_swap: pushl $zip2 pushl $zip1 call swap # Global Var # Global Var Revisiting swap int zip1 = 15213; int zip2 = 98195; void call_swap() swap(&zip1, &zip2); Calling swap from call_swap call_swap: pushl $zip2 pushl $zip1 call swap # Global Var # Global Var void swap(int *, int *) int t0 = *; int t1 = *; * = t1; * = t0; void swap(int *, int *) int t0 = *; int t1 = *; * = t1; * = t0; &zip2 &zip1 Resulting

12 Revisiting swap swap Setup #1 void swap(int *, int *) int t0 = *; int t1 = *; * = t1; * = t0; swap: pushl movl, pushl %ebx movl 12(),%ecx movl 8(),%edx movl (%ecx),%eax movl (%edx),%ebx movl %eax,(%edx) movl %ebx,(%ecx) Set Up Body Entering &zip2 &zip1 Resulting? movl -4(),%ebx movl, popl Finish swap: pushl movl, pushl %ebx swap Setup #1 swap Setup #2 Entering Resulting Entering Resulting &zip2 &zip1 Old &zip2 &zip1 Old swap: pushl movl, pushl %ebx swap: pushl movl, pushl %ebx

13 swap Setup #3 swap Body Entering Resulting Entering Resulting &zip2 &zip1 swap: pushl movl, pushl %ebx Old Old %ebx &zip2 &zip1 movl 12(),%ecx # get movl 8(),%edx # get... Offset relative to new Old Old %ebx swap Finish #1 swap Finish #1 swap s Resulting? swap s Resulting Old Old %ebx Old Old %ebx Old Old %ebx movl -4(),%ebx movl, popl movl -4(),%ebx movl, popl Observation: Saved and restored register %ebx

14 swap Finish #2 swap Finish #3 swap s Resulting swap s Resulting Old Old %ebx Old Old Old %ebx movl -4(),%ebx movl, popl movl -4(),%ebx movl, popl swap Finish #4 Disassembled swap swap s Old Old %ebx Resulting a4 <swap>: 80483a4: 55 push 80483a5: 89 e5 mov, 80483a7: 53 push %ebx 80483a8: 8b mov 0x8(),%edx 80483ab: 8b 4d 0c mov 0xc(),%ecx 80483ae: 8b 1a mov (%edx),%ebx 80483b0: 8b 01 mov (%ecx),%eax 80483b2: mov %eax,(%edx) 80483b4: mov %ebx,(%ecx) 80483b6: 5b pop %ebx mov, 80483b7: c9 leave pop 80483b8: c3 movl -4(),%ebx movl, popl Calling Code : e8 96 ff ff ff call 80483a4 <swap> e: 8b 45 f8 mov 0xfffffff8(),%eax

15 swap Finish #4 swap s Old Old %ebx movl -4(),%ebx movl, popl Resulting Observation Saved & restored register %ebx Didn t do so for %eax, %ecx, or %edx Section 5: Procedures & s s in memory and stack operations The stack used to keep track of procedure calls Return addresses and urn values -based languages The Linux stack frame Passing arguments on the stack Allocating local variables on the stack Register-saving conventions Procedures and stacks on x64 architecture Register Saving and Local Variables Register Saving Conventions When procedure calls : is the caller is the callee Register Saving Conventions When procedure calls : is the caller is the callee Can a register be used for temporary storage? : movl $45, %edx call addl %edx, %eax : movl 8(), %edx addl $98195, %edx Can a register be used for temporary storage? Conventions Caller Save Caller saves temporary values in its frame before calling Callee Save Callee saves temporary values in its frame before using Contents of register %edxoverwritten by Register Saving and Local Variables Register Saving and Local Variables

16 IA32/Linux Register Usage %eax, %edx, %ecx Caller saves prior to call if values are used later %eax also used to urn integer value %ebx, %esi, %edi Callee saves if wants to use them Caller-Save Temporaries Callee-Save Temporaries Special %eax %edx %ecx %ebx %esi %edi, special form of callee save restored to original values upon exit from procedure : Pointers to Local Variables Recursive Procedure void s_helper (int x, int *accum) if (x <= 1) urn; else int z = *accum * x; *accum = z; s_helper (x-1,accum); Pass pointer to update location Top-Level Call intsfact(int x) intval = 1; s_helper(x, &val); urn val; Register Saving and Local Variables Register Saving and Local Variables Creating & Initializing Pointer int sfact(int x) int val = 1; s_helper(x, &val); urn val; Initial part of sfact _sfact: pushl # Save movl movl, # Set subl subl $16, # Add 16 bytes movl movl 8(),%edx # edx = x movl movl $1,-4() # val = 1 Temp. Unused Space Variable val must be stored on stack Because: Need to create pointer to it Compute pointer as -4() Push on stack as second argument 8 4 x Rtnadr 0 Old -4 val = Passing Pointer int sfact(int x) int val = 1; s_helper(x, &val); urn val; Calling s_helper from sfact at time of call: leal -4(),%eax # Compute &val pushl %eax # Push on stack pushl %edx # Push x call call s_helper # call movl -4(),%eax # Return val # Finish x Rtnadr Old val=x! = 1 Unused &val x Variable val must be stored on stack Because: Need to create pointer to it Compute pointer as -4() Push on stack as second argument Register Saving and Local Variables Register Saving and Local Variables

17 IA 32 Procedure Summary Important points: IA32 procedures are a combination of instructions and conventions Conventions prevent functions from disrupting each other is the right data structure for procedure call / urn If P calls Q, then Q urns before P Recursion handled by normal calling conventions Can safely store values in local stack frame and in callee-saved registers Put function arguments at top of stack Result urned in %eax Register Saving and Local Variables Caller Frame Arguments Return Addr Old Saved Registers + Local Variables Argument Build Section 5: Procedures & s s in memory and stack operations The stack used to keep track of procedure calls Return addresses and urn values -based languages The Linux stack frame Passing arguments on the stack Allocating local variables on the stack Register-saving conventions Procedures and stacks on x64 architecture x64 Procedures and s x86-64 Procedure Calling Convention x bit Registers: Usage Conventions Doubling of registers makes us less dependent on stack Store argument in registers Store temporary variables in registers %rax %rbx Return value Callee saved %r8 %r9 Argument #5 Argument #6 What do we do if we have too many arguments or too many temporary variables? %rcx %rdx Argument #4 Argument #3 %r10 %r11 Caller saved Caller Saved %rsi Argument #2 %r12 Callee saved %rdi Argument #1 %r13 Callee saved %rsp pointer %r14 Callee saved %rbp Callee saved %r15 Callee saved x64 Procedures and s x64 Procedures and s

18 Revisiting swap, IA32 vs. x86-64 versions X86-64 procedure call highlights swap: pushl movl, pushl %ebx movl 12(),%ecx movl 8(),%edx movl (%ecx),%eax movl (%edx),%ebx movl %eax,(%edx) movl %ebx,(%ecx) movl -4(),%ebx movl, popl Set Up Body Finish x64 Procedures and s swap (64-bit long ints): movq (%rdi), %rdx movq (%rsi), %rax movq %rax, (%rdi) movq %rdx, (%rsi) Arguments passed in registers First () in %rdi, second () in %rsi 64-bit pointers No stack operations required (except ) Avoiding stack Can hold all local information in registers Arguments (up to first 6) in registers Faster to get these values from registers than from stack in memory Local variables also in registers (if there is room) callqinstruction stores 64-bit urn address on stack Address pushed onto stack, decrementing %rsp by 8 No frame pointer All references to stack frame made relative to %rsp; eliminates need to update /%rbp, which is now available for general-purpose use Functions can access memory up to 128 bytes beyond %rsp: the red zone Can store some temps on stack without altering %rsp Registers still designated caller-saved or callee-saved x64 Procedures and s x86-64 Frames Often (ideally), x86-64 functions need no stack frame at all Just a urn address is pushed onto the stack when a function call is made A function doesneed a stack frame when it: Has too many local variables to hold in registers Has local variables that are arrays or structs Uses the address-of operator (&) to compute the address of a local variable Calls another function that takes more than six arguments Needs to save the state of callee-save registers before modifying them long int call_proc() long x1 = 1; int x2 = 2; short x3 = 3; char x4 = 4; proc(x1, &x1, x2, &x2, x3, &x3, x4, &x4); urn (x1+x2)*(x3-x4); Return address to caller of call_proc call_proc: subq $32,%rsp movq $1,16(%rsp) movl $2,24(%rsp) movw $3,28(%rsp) movb $4,31(%rsp) %rsp NB: Details may vary depending on compiler. x64 Procedures and s x64 Procedures and s

19 long int call_proc() long x1 = 1; int x2 = 2; short x3 = 3; char x4 = 4; proc(x1, &x1, x2, &x2, x3, &x3, x4, &x4); urn (x1+x2)*(x3-x4); x4 Return address to caller of call_proc x3 x1 x2 call_proc: subq $32,%rsp movq $1,16(%rsp) movl $2,24(%rsp) movw $3,28(%rsp) movb $4,31(%rsp) %rsp long int call_proc() long x1 = 1; int x2 = 2; short x3 = 3; char x4 = 4; proc(x1, &x1, x2, &x2, x3, &x3, x4, &x4); urn (x1+x2)*(x3-x4); x4 Return address to caller of call_proc x3 x1 Arg8 Arg 7 x2 call_proc: movq $1,%rdi leaq 16(%rsp),%rsi movl $2,%edx leaq 24(%rsp),%rcx movl $3,%r8d leaq 28(%rsp),%r9 movl $4,(%rsp) leaq 31(%rsp),%rax movq %rax,8(%rsp) call proc %rsp Arguments passed in (in order): rdi, rsi, rdx, rcx, r8, r9, then stack x64 Procedures and s x64 Procedures and s long int call_proc() long x1 = 1; int x2 = 2; short x3 = 3; char x4 = 4; proc(x1, &x1, x2, &x2, x3, &x3, x4, &x4); urn (x1+x2)*(x3-x4); x4 Return address to caller of call_proc x3 x1 Arg8 Arg7 x2 Return address to line after call to proc call_proc: movq $1,%rdi leaq 16(%rsp),%rsi movl $2,%edx leaq 24(%rsp),%rcx movl $3,%r8d leaq 28(%rsp),%r9 movl $4,(%rsp) leaq 31(%rsp),%rax movq %rax,8(%rsp) call proc %rsp Arguments passed in (in order): rdi, rsi, rdx, rcx, r8, r9, then stack long int call_proc() long x1 = 1; int x2 = 2; short x3 = 3; char x4 = 4; proc(x1, &x1, x2, &x2, x3, &x3, x4, &x4); urn (x1+x2)*(x3-x4); x4 Return address to caller of call_proc x3 x1 Arg8 Arg7 x2 call_proc: movswl 28(%rsp),%eax movsbl 31(%rsp),%edx subl %edx,%eax cltq movslq 24(%rsp),%rdx addq 16(%rsp),%rdx imulq %rdx,%rax addq $32,%rsp %rsp x64 Procedures and s x64 Procedures and s

20 long int call_proc() long x1 = 1; int x2 = 2; short x3 = 3; char x4 = 4; proc(x1, &x1, x2, &x2, x3, &x3, x4, &x4); urn (x1+x2)*(x3-x4); Return address to caller of call_proc call_proc: movswl 28(%rsp),%eax movsbl 31(%rsp),%edx subl %edx,%eax cltq movslq 24(%rsp),%rdx addq 16(%rsp),%rdx imulq %rdx,%rax addq $32,%rsp %rsp x86-64 Procedure Summary Heavy use of registers (faster than using stack in memory) Parameter passing More temporaries since more registers Minimal use of stack Sometimes none When needed, allocate/deallocate entire frame at once No more frame pointer: address relative to stack pointer More room for compiler optimizations Prefer to store data in registers rather than memory Minimize modifications to stack pointer x64 Procedures and s x64 Procedures and s

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 movq... popq %rbp %rsp,

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

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

Procedures and the Call Stack

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

More information

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

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

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

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

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

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

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

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

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

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

Machine- Level Programming III: Switch Statements and IA32 Procedures

Machine- Level Programming III: Switch Statements and IA32 Procedures Machine- Level Programming III: Switch Statements and IA32 Procedures CS 485: Systems Programming Fall 2015 Instructor: James Griffioen Adapted from slides by R. Bryant and D. O Hallaron (hjp://csapp.cs.cmu.edu/public/instructors.html)

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

Assembly Programming IV

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

More information

IA32 Stack. Stack BoDom. Region of memory managed with stack discipline Grows toward lower addresses. Register %esp contains lowest stack address

IA32 Stack. Stack BoDom. Region of memory managed with stack discipline Grows toward lower addresses. Register %esp contains lowest stack address IA32 Procedures 1 IA32 Stack Region of memory managed with stack discipline Grows toward lower addresses Stack BoDom Increasing Addresses Register contains lowest stack address address of top element Stack

More information

The Stack & Procedures

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

More information

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

Machine Program: Procedure. Zhaoguo Wang

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

More information

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

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

More information

Page 1. IA32 Stack CISC 360. Machine-Level Programming III: Procedures Sept. 22, IA32 Stack Popping Stack Bottom. IA32 Stack Pushing

Page 1. IA32 Stack CISC 360. Machine-Level Programming III: Procedures Sept. 22, IA32 Stack Popping Stack Bottom. IA32 Stack Pushing CISC 36 Machine-Level Programming III: Procedures Sept. 22, 2 IA32 Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address address of top element

More information

CS429: Computer Organization and Architecture

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

More information

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

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

More information

Machine-level Programs Procedure

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

More information

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-Level Programming III: Procedures

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

More information

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

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

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

More information

Data Representa/ons: IA32 + x86-64

Data Representa/ons: IA32 + x86-64 X86-64 Instruc/on Set Architecture Instructor: Sanjeev Se(a 1 Data Representa/ons: IA32 + x86-64 Sizes of C Objects (in Bytes) C Data Type Typical 32- bit Intel IA32 x86-64 unsigned 4 4 4 int 4 4 4 long

More information

x86-64 Programming III

x86-64 Programming III x86-64 Programming III CSE 351 Summer 2018 Instructor: Justin Hsia Teaching Assistants: Josie Lee Natalie Andreeva Teagan Horkan http://xkcd.com/1652/ Administrivia Homework 2 due Wednesday (7/11) Lab

More information

Assembly Programming IV

Assembly Programming IV Assembly Programming IV CSE 410 Winter 2017 Instructor: Justin Hsia Teaching Assistants: Kathryn Chan, Kevin Bi, Ryan Wong, Waylon Huang, Xinyu Sui The Data That Turned the World Upside Down The company

More information

x86 Programming I CSE 351 Winter

x86 Programming I CSE 351 Winter x86 Programming I CSE 351 Winter 2017 http://xkcd.com/409/ Administrivia Lab 2 released! Da bomb! Go to section! No Luis OH Later this week 2 Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals

More information

x86-64 Programming III & The Stack

x86-64 Programming III & The Stack x86-64 Programming III & The Stack CSE 351 Winter 2018 Instructor: Mark Wyse Teaching Assistants: Kevin Bi Parker DeWilde Emily Furst Sarah House Waylon Huang Vinny Palaniappan http://xkcd.com/1652/ Administrative

More information

The Stack & Procedures

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

More information

6.1. CS356 Unit 6. x86 Procedures Basic Stack Frames

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

More information

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

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

More information

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

The Hardware/Software Interface CSE351 Spring 2015

The Hardware/Software Interface CSE351 Spring 2015 The Hardware/Software Interface CSE351 Spring 2015 Lecture 7 Instructor: Katelin Bailey Teaching Assistants: Kaleo Brandt, Dylan Johnson, Luke Nelson, Alfian Rizqi, Kritin Vij, David Wong, and Shan Yang

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

hnp://

hnp:// The bots face off in a tournament against one another and about an equal number of humans, with each player trying to score points by elimina&ng its opponents. Each player also has a "judging gun" in addi&on

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 x86-64 solutions Pertinent instructions and conventions 2 Function Call Problems (1) Calling and returning

More information

Building an Executable

Building an Executable Building an Executable CSE 351 Summer 2018 Instructor: Justin Hsia Teaching Assistants: Josie Lee Natalie Andreeva Teagan Horkan http://xkcd.com/1790/ Administrivia Lab 2 due Monday (7/16) Homework 3 due

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

Machine-Level Programming (2)

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

More information

x86 Programming I CSE 351 Autumn 2016 Instructor: Justin Hsia

x86 Programming I CSE 351 Autumn 2016 Instructor: Justin Hsia x86 Programming I CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun http://xkcd.com/409/

More information

Systems Programming and Computer Architecture ( )

Systems Programming and Computer Architecture ( ) Systems Group Department of Computer Science ETH Zürich Systems Programming and Computer Architecture (252-0061-00) Timothy Roscoe Herbstsemester 2016 AS 2016 Compiling C Control Flow 1 8: Compiling C

More information

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

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

More information

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Roadmap. Java: Assembly language: OS: Machine code: Computer system: 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 movq... popq ret %rbp %rsp, %rbp

More information

Machine- Level Representa2on: Procedure

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

More information

Lecture 4 CIS 341: COMPILERS

Lecture 4 CIS 341: COMPILERS Lecture 4 CIS 341: COMPILERS CIS 341 Announcements HW2: X86lite Available on the course web pages. Due: Weds. Feb. 7 th at midnight Pair-programming project Zdancewic CIS 341: Compilers 2 X86 Schematic

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

Machine/Assembler Language Putting It All Together

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

More information

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p text C program (p1.c p2.c) Compiler (gcc -S) text Asm

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

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

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

More information

Machine- Level Programming III: Switch Statements and IA32 Procedures

Machine- Level Programming III: Switch Statements and IA32 Procedures Machine- Level Programming III: Switch Statements and IA32 Procedures 15-213: Introduc;on to Computer Systems 6 th Lecture, Sep. 9, 2010 Instructors: Randy Bryant and Dave O Hallaron Today Switch statements

More information

Arrays. CSE 351 Autumn Instructor: Justin Hsia

Arrays. CSE 351 Autumn Instructor: Justin Hsia rrays CSE 351 utumn 2016 Instructor: Justin Hsia Teaching ssistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun http://xkcd.com/1513/

More information

L14: Structs and Alignment. Structs and Alignment. CSE 351 Spring Instructor: Ruth Anderson

L14: Structs and Alignment. Structs and Alignment. CSE 351 Spring Instructor: Ruth Anderson Structs and Alignment CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Lab 2 due TONIGHT

More information

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

CSE351 Autumn 2014 Midterm Exam (29 October 2014) CSE351 Autumn 2014 Midterm Exam (29 October 2014) Please read through the entire examination first! We designed this exam so that it can be completed in 50 minutes and, hopefully, this estimate will prove

More information

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

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

More information

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

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

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

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

Structs and Alignment CSE 351 Spring

Structs and Alignment CSE 351 Spring Structs and Alignment CSE 351 Spring 2018 http://xkcd.com/1168/ Administrivia Homework 3 due Wednesday Lab 3 released, due next week Lab 2 and midterm will be graded this week [in that order] 2 Roadmap

More information

Arrays. CSE 351 Autumn Instructor: Justin Hsia

Arrays. CSE 351 Autumn Instructor: Justin Hsia rrays CSE 351 utumn 2017 Instructor: Justin Hsia Teaching ssistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/1270/ dministrivia

More information

Function Calls and Stack

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

More information

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

CS 107. Lecture 13: Assembly Part III. Friday, November 10, Stack "bottom".. Earlier Frames. Frame for calling function P. Increasing address

CS 107. Lecture 13: Assembly Part III. Friday, November 10, Stack bottom.. Earlier Frames. Frame for calling function P. Increasing address CS 107 Stack "bottom" Earlier Frames Lecture 13: Assembly Part III Argument n Friday, November 10, 2017 Computer Systems Increasing address Argument 7 Frame for calling function P Fall 2017 Stanford University

More information

Credits and Disclaimers

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

More information

CSE 351 Midterm Exam Spring 2016 May 2, 2015

CSE 351 Midterm Exam Spring 2016 May 2, 2015 Name: CSE 351 Midterm Exam Spring 2016 May 2, 2015 UWNetID: Solution Please do not turn the page until 11:30. Instructions The exam is closed book, closed notes (no calculators, no mobile phones, no laptops,

More information

Intel x86-64 and Y86-64 Instruction Set Architecture

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

More information

Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT

Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT CS33 Intro to Computer Systems XI 1 Copyright 2017 Thomas

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 7 LAST TIME Dynamic memory allocation and the heap: A run-time facility that satisfies multiple needs: Programs can use widely varying, possibly

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

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

CSE351 Autumn 2014 Midterm Exam (29 October 2014) CSE351 Autumn 2014 Midterm Exam (29 October 2014) (Version A) Please read through the entire examination first! We designed this exam so that it can be completed in 50 minutes and, hopefully, this estimate

More information

CS 107 Lecture 10: Assembly Part I

CS 107 Lecture 10: Assembly Part I CS 107 Lecture 10: Assembly Part I Friday, February 9th, 2018 Computer Systems Winter 2018 Stanford University Computer Science Department Reading: Course Reader: x86-64 Assembly Language, Textbook: Chapter

More information

Assembly I: Basic Operations. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly I: Basic Operations. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Assembly I: Basic Operations Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Basic Execution Environment RAX RBX RCX RDX RSI RDI RBP RSP R8 R9 R10

More information

Structs & Alignment. CSE 351 Autumn Instructor: Justin Hsia

Structs & Alignment. CSE 351 Autumn Instructor: Justin Hsia Structs & Alignment CSE 351 Autumn 2018 Instructor: Justin Hsia Teaching Assistants: Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson Sophie

More information

Today: Machine Programming I: Basics

Today: Machine Programming I: Basics Today: Machine Programming I: Basics History of Intel processors and architectures C, assembly, machine code Assembly Basics: Registers, operands, move Intro to x86-64 1 Intel x86 Processors Totally dominate

More information

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

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

x86-64 Programming I CSE 351 Summer 2018 Instructor: Justin Hsia Teaching Assistants: Josie Lee Natalie Andreeva Teagan Horkan

x86-64 Programming I CSE 351 Summer 2018 Instructor: Justin Hsia Teaching Assistants: Josie Lee Natalie Andreeva Teagan Horkan x86-64 Programming I CSE 351 Summer 2018 Instructor: Justin Hsia Teaching Assistants: Josie Lee Natalie Andreeva Teagan Horkan http://www.smbc-comics.com/?id=2999 Administrivia Lab 1b due on Thursday (7/5)

More information

Areas for growth: I love feedback

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

More information

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION Today: Machine Programming I: Basics History of Intel processors and architectures C, assembly, machine code Assembly Basics:

More information

How Software Executes

How Software Executes How Software Executes CS-576 Systems Security Instructor: Georgios Portokalidis Overview Introduction Anatomy of a program Basic assembly Anatomy of function calls (and returns) Memory Safety Programming

More information

Instruction Set Architectures

Instruction Set Architectures Instruction Set Architectures! ISAs! Brief history of processors and architectures! C, assembly, machine code! Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface

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

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

CSE 351 Section 4 GDB and x86-64 Assembly Hi there! Welcome back to section, we re happy that you re here

CSE 351 Section 4 GDB and x86-64 Assembly Hi there! Welcome back to section, we re happy that you re here CSE 351 Section 4 GDB and x86-64 Assembly Hi there! Welcome back to section, we re happy that you re here x86-64 Assembly Language Assembly language is a human-readable representation of machine code instructions

More information

Where We Are. Optimizations. Assembly code. generation. Lexical, Syntax, and Semantic Analysis IR Generation. Low-level IR code.

Where We Are. Optimizations. Assembly code. generation. Lexical, Syntax, and Semantic Analysis IR Generation. Low-level IR code. Where We Are Source code if (b == 0) a = b; Low-level IR code Optimized Low-level IR code Assembly code cmp $0,%rcx cmovz %rax,%rdx Lexical, Syntax, and Semantic Analysis IR Generation Optimizations Assembly

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

Structs and Alignment

Structs and Alignment Structs and Alignment CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun

More information

Machine Level Programming I: Basics

Machine Level Programming I: Basics Carnegie Mellon Machine Level Programming I: Basics Kai Shen Why do I care for machine code? Chances are, you ll never write programs in machine code Compilers are much better & more patient than you are

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 4 LAST TIME Enhanced our processor design in several ways Added branching support Allows programs where work is proportional to the input values

More information

Carnegie Mellon. 5 th Lecture, Jan. 31, Instructors: Todd C. Mowry & Anthony Rowe

Carnegie Mellon. 5 th Lecture, Jan. 31, Instructors: Todd C. Mowry & Anthony Rowe Machine Level Programming I: Basics 15 213/18 213: 213: Introduction to Computer Systems 5 th Lecture, Jan. 31, 2012 Instructors: Todd C. Mowry & Anthony Rowe 1 Today: Machine Programming gi: Basics History

More information