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

Size: px
Start display at page:

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

Transcription

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

2 Mechanisms in Procedures Passing control To beginning of procedure code Back to urn point Passing data Procedure arguments Return value Memory management Allocate during procedure execution Deallocate upon urn All implemented with machine instructions int P(...) {.. y = Q(x); print(y);. } int Q(int i) { } int t = 3*i; int v[10];.. urn v[t]; 2

3 x86-64 Stack Region of memory managed with stack discipline Last-In, First-Out (LIFO) Push & Pop Grows toward lower addresses Register contains lowest stack address Address of top element Stack Pointer Stack Bottom Increasing Addresses Stack Grows Down Stack Top 3

4 x86-64 Stack: Push pushq Src Fetch operand at Src Decrement by 8 Write operand at address given by Stack Bottom Increasing Addresses Stack Pointer -8 Stack Grows Down Stack Top 4

5 x86-64 Stack: Pop popq Dest Read value at address given by Increment by 8 Store value at Dest (must be a register) Stack Bottom Increasing Addresses Stack Pointer +8 Stack Grows Down Stack Top 5

6 x86-64 Stack: Example Stack operation examples pushq %rax popq %rdx 0x210 0x210 0x210 0x208 0x208 0x208 0x x x x1f x1f8 213 %rax 213 %rax 213 %rax 213 %rdx 555 %rdx 555 %rdx x200 0x108 0x1f8 0x104 0x200 6

7 Procedure Control Flow Use stack to support procedure call and urn Procedure call: call label Push urn address on stack Address of the next instruction right after call Jump to label Procedure urn: Pop address from stack Jump to address 7

8 Example <main>: : 48 8d f8 lea -0x8(), 40054b: bf 0a mov $0xa,%edi : e callq <fact> : c7 mov %rax,%rdi : e callq 40057e <print> 40055d: b mov $0x0,%eax : 48 8d lea 0x8(), : c3 q <fact>: : b mov $0x1,%eax 40056d: eb 08 jmp <fact+0xf> 40056f: 48 0f af c7 imul %rdi,%rax : ef 01 sub $0x1,%rdi : ff 01 cmp $0x1,%rdi 40057b: 7f f2 jg 40056f <fact+0x7> 40057d: c3 q 8

9 Procedure Call Example : e callq <fact> : c7 mov %rax,%rdi callq x x =0x x120 0x118 0x x120 0x118 0x x108 0x x110 0x108 %rip 0x %rip 0x804854e 0x %rip is program counter 9

10 Procedure Return Example 40057d: c3 q 0x120 0x118 0x110 0x108 0x120 0x x110 0x x x x108 0x104 0x110 %rip 0x40057d %rip 0x x %rip is program counter 10

11 Passing Arguments First 6 arguments: Diane s silk dress costs $89 %rdi %rsi %rdx %rcx Remaining arguments: Push the rest on the stack in reverse order Only allocate stack space when needed %r8 %r9 Return value %rax Arg n Arg 8 Arg 7 Increasing Addresses 11

12 Stack-based Languages Languages that support recursion (e.g. C, C++, Pascal, Java) Code must be Reentrant Multiple simultaneous instantiations of single procedure Need some place to store state of each instantiation Arguments, local variables, urn address Stack discipline State for given procedure needed for limited time From when called to when urn Callee urns before caller does Stack allocated in frames State for single procedure instantiation 12

13 Stack Frame Contents Return information Arguments Local variables & temp space Frame Pointer (Optional) %rbp Management Set-up code: space allocated Stack Pointer when enter procedure Finish code: deallocate when urn Stack pointer indicates stack top Optional frame pointer %rbp indicates start of current frame Previous Frame Frame for proc Stack Top 13

14 Stack Frames: Example (1) Code Structure yoo( ) { who(); } who( ) { (); (); } Procedure recursive ( ) { (); } Call Chain yoo who 14

15 Stack Frames: Example (2) yoo( ) { who(); } Call Chain yoo Frame Pointer %rbp Stack Pointer yoo 15

16 Stack Frames: Example (3) who( ) { (); (); Call Chain yoo who Frame Pointer %rbp Stack Pointer yoo who } 16

17 Stack Frames: Example (4) ( ) { (); } Call Chain yoo who Frame Pointer %rbp Stack Pointer yoo who 17

18 Stack Frames: Example (5) ( ) { (); } Call Chain yoo who Frame Pointer %rbp Stack Pointer yoo who 18

19 Stack Frames: Example (6) ( ) { (); } Call Chain yoo who yoo who Frame Pointer %rbp Stack Pointer 19

20 Stack Frames: Example (7) ( ) { (); } Call Chain yoo who Frame Pointer %rbp Stack Pointer yoo who 20

21 Stack Frames: Example (8) ( ) { (); } Call Chain yoo who Frame Pointer %rbp Stack Pointer yoo who 21

22 Stack Frames: Example (9) who( ) { (); (); } Call Chain yoo who Frame Pointer %rbp Stack Pointer yoo who 22

23 Stack Frames: Example (10) ( ) { } Call Chain yoo who Frame Pointer %rbp Stack Pointer yoo who 23

24 Stack Frames: Example (11) who( ) { (); (); } Call Chain yoo who Frame Pointer %rbp Stack Pointer yoo who 24

25 Stack Frames: Example (12) yoo( ) { who(); } Call Chain yoo who Frame Pointer %rbp Stack Pointer yoo 25

26 x86-64/linux Stack Frame Current stack frame ( Top to Bottom) Argument build: Parameters for function about to call Local variables if can t keep in registers Saved register context Old frame pointer (optional) Caller stack frame Return address Pushed by call instruction Arguments for this call Caller Frame Frame Pointer (optional) %rbp Stack Pointer Arguments 7+ Return Addr Old %rbp Saved Registers + Local Variables Argument Build 26

27 Revisiting Swap long v1 = 1111; long v2 = 2222; void swap (long *xp, long *yp) { long t = *xp; *xp = *yp; *yp = t; } int main (void) { swap (&v1, &v2);... } v2: v1:.quad quad swap: movq (%rdi), %rax movq (%rsi), %rdx movq %rdx, (%rdi) movq %rax, (%rsi) main:... movq movq call... $v2, %rsi $v1, %rdi swap 27

28 Register Saving Problem When procedure yoo() calls who(): yoo() is the caller, who() is the callee Can register be used for temporary storage? yoo: movq $15213, %rdx call who addq %rdx, %rax who: subq $91125, %rdx Contents of register %rdx overwritten by who() 28

29 Register Saving Conventions Caller saved registers Caller saves temporary values in its frame before the call Contents of these registers can be modified as a result of procedure call x86-64: %rax, %rdi, %rsi, %rdx, %rcx, %r8, %r9, %r10, %r11 Callee saved registers Callee saves temporary values in its frame before using Callee restores them before urning to caller The contents of these registers are preserved across a procedure call x86-64: %rbx, %r12, %r13, %r14, %r15, %rbp 29

30 x86-64/linux Register Usage (1) %rax Return value Also caller-saved Can be modified by procedure %rdi,, %r9 Arguments Also caller-saved Can be modified by procedure %r10, %r11 Caller-saved Can be modified by procedure Return value Arguments Caller-saved temporaries %rax %rdi %rsi %rdx %rcx %r8 %r9 %r10 %r11 30

31 x86-64/linux Register Usage (2) %rbx, %r12, %r13, %r14, %r15 Callee-saved Callee must save & restore %rbp Callee-saved Callee must save & restore May be used as frame pointer Special from of callee save Restored to original value upon exit from procedure Callee-saved Temporaries Special %rbx %r12 %r13 %r14 %r15 %rbp 31

32 Recursive Factorial: rfact Registers %rax used without first saving %rbx used, but save at beginning & restore at end long rfact(long x) { long rval; if (x <= 1) urn 1; rval = rfact(x-1); urn rval * x; } rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx 32

33 Example: rfact(3) RetAddr Registers %rdi 3 %rax? Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx? 33

34 Example: rfact(3) RetAddr? Registers %rdi 3 %rax? Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx? 34

35 Example: rfact(3) RetAddr? Registers %rdi 3 %rax? Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 3 35

36 Example: rfact(3) RetAddr? Registers %rdi 2 %rax? Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 3 36

37 Example: rfact(3) RetAddr? A Registers %rdi 2 %rax? Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 3 37

38 Example: rfact(3) RetAddr? A Registers %rdi 2 %rax? Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 3 38

39 Example: rfact(3) RetAddr? A 3 Registers %rdi 2 %rax? Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 3 39

40 Example: rfact(3) RetAddr? A 3 Registers %rdi 2 %rax? Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 2 40

41 Example: rfact(3) RetAddr? A 3 Registers %rdi 1 %rax? Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 2 41

42 Example: rfact(3) RetAddr? A 3 A Registers %rdi 1 %rax? Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 2 42

43 Example: rfact(3) RetAddr? A 3 A Registers %rdi 1 %rax? Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 2 43

44 Example: rfact(3) RetAddr? A 3 A Registers %rdi 1 %rax 1 Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 2 44

45 Example: rfact(3) RetAddr? A 3 A Registers %rdi 1 %rax 1 Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 2 45

46 Example: rfact(3) RetAddr? A 3 A Registers %rdi 1 %rax 2 Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 2 46

47 Example: rfact(3) RetAddr? A 3 A Registers %rdi 1 %rax 2 Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 3 47

48 Example: rfact(3) RetAddr? A 3 A Registers %rdi 1 %rax 2 Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 3 48

49 Example: rfact(3) RetAddr? A 3 A Registers %rdi 1 %rax 6 Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx 3 49

50 Example: rfact(3) RetAddr? A 3 A Registers %rdi 1 %rax 6 Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx? 50

51 Example: rfact(3) RetAddr? A 3 A Registers %rdi 1 %rax 6 Lower Address %rip rfact: cmpq $1, %rdi jle.l3 pushq %rbx movq %rdi, %rbx leaq -1(%rdi), %rdi call rfact A: imulq %rbx, %rax jmp.l2.l3: movl $1, %eax.l2: popq %rbx %rbx? 51

52 Observations about Recursion Handled without special consideration Stack frames mean each function call has private storage Saved registers + local variables Saved urn address Register saving conventions prevent one function call from corrupting another s data Unless the C code explicitly does so (e.g. buffer overflow) Stack discipline follows call / urn pattern If P calls Q, then Q urns before P Last-In, First-Out Also works for mutual recursion P calls Q; Q calls P 52

53 Summary Stack is the right data structure for procedure call / urn Private storage for each instance of procedure call Recursion handled by normal calling conventions Mechanisms Call,, push, pop, etc. instructions Registers for passing arguments and urn value Stack memory Policies Register usage (caller / callee save, %rbp & ) Stack frame organization 53

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

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

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

Machine-Level Programming III: Procedures

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

More information

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

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

More information

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

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

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

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

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

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

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

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

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

%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

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

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

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

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

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

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

Compiling C Programs Into x86-64 Assembly Programs

Compiling C Programs Into x86-64 Assembly Programs CSE 2421: Systems I Low-Level Programming and Computer Organization Compiling C Programs Into x86-64 Assembly Programs Part A: Function Calling Read/Study: Bryant 3.7.1-3.7.6 Presentation K Gojko Babić

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

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

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

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

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

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

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

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

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

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

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

More information

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

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

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

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

Do not turn the page until 5:10.

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

More information

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

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

1 Number Representation(10 points)

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

More information

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

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

More information

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

x86 Programming II CSE 351 Winter

x86 Programming II CSE 351 Winter x86 Programming II CSE 351 Winter 2017 http://xkcd.com/1652/ Administrivia 2 Address Computation Instruction v leaq src, dst lea stands for load effective address src is address expression (any of the

More information

CSE 351 Midterm - Winter 2015

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

More information

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

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

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

Topics of this Slideset. CS429: Computer Organization and Architecture. Instruction Set Architecture. Why Y86? Instruction Set Architecture

Topics of this Slideset. CS429: Computer Organization and Architecture. Instruction Set Architecture. Why Y86? Instruction Set Architecture Topics of this Slideset CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Intro to Assembly language Programmer visible state Y86

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

CS356: Discussion #15 Review for Final Exam. Marco Paolieri Illustrations from CS:APP3e textbook

CS356: Discussion #15 Review for Final Exam. Marco Paolieri Illustrations from CS:APP3e textbook CS356: Discussion #15 Review for Final Exam Marco Paolieri (paolieri@usc.edu) Illustrations from CS:APP3e textbook Processor Organization Pipeline: Computing Throughput and Delay n 1 2 3 4 5 6 clock (ps)

More information

CSE 351 Midterm - Winter 2015 Solutions

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

More information

Lecture 3 CIS 341: COMPILERS

Lecture 3 CIS 341: COMPILERS Lecture 3 CIS 341: COMPILERS HW01: Hellocaml! Announcements is due tomorrow tonight at 11:59:59pm. HW02: X86lite Will be available soon look for an announcement on Piazza Pair-programming project Simulator

More information

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Assembly II: Control Flow Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Processor State (x86-64) RAX 63 31 EAX 0 RBX EBX RCX RDX ECX EDX General-purpose

More information

CSE351 Spring 2018, Midterm Exam April 27, 2018

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

More information

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

Computer Organization: A Programmer's Perspective

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

More information

CSCI 2021: x86-64 Control Flow

CSCI 2021: x86-64 Control Flow CSCI 2021: x86-64 Control Flow Chris Kauffman Last Updated: Mon Mar 11 11:54:06 CDT 2019 1 Logistics Reading Bryant/O Hallaron Ch 3.6: Control Flow Ch 3.7: Procedure calls Goals Jumps and Control flow

More information

L08: Assembly Programming II. Assembly Programming II. CSE 351 Spring Guest Lecturer: Justin Hsia. Instructor: Ruth Anderson

L08: Assembly Programming II. Assembly Programming II. CSE 351 Spring Guest Lecturer: Justin Hsia. Instructor: Ruth Anderson Assembly Programming II CSE 351 Spring 2017 Guest Lecturer: Justin Hsia Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis

More information

C to Machine Code x86 basics: Registers Data movement instructions Memory addressing modes Arithmetic instructions

C to Machine Code x86 basics: Registers Data movement instructions Memory addressing modes Arithmetic instructions C to Machine Code x86 basics: Registers Data movement instructions Memory addressing modes Arithmetic instructions Program, Application Software Hardware next few weeks Programming Language Compiler/Interpreter

More information

Machine Language CS 3330 Samira Khan

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

More information

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: October 11, 2017 at 17:42 CS429 Slideset 6: 1 Topics of this Slideset

More information

Question 1: Number Representation

Question 1: Number Representation Question 1: Number Representation (A) What is the value of the char 0b 1101 1101 in decimal? If x = 0xDD, x = 0x23 = 2 5 +3 = 35 Also accepted unsigned: 0xDD = (16+1)*13 = 221-35 or 221 (B) What is the

More information

Processor state. Information about currently executing program. %rax, %rdi, ... %r14 %r15. %rsp. %rip CF ZF SF OF. Temporary data

Processor state. Information about currently executing program. %rax, %rdi, ... %r14 %r15. %rsp. %rip CF ZF SF OF. Temporary data Processor state Information about currently executing program Temporary data %rax, %rdi, current parameters, local variables Location of runtime stack %rsp Location of current instruction %rip Status of

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

Buffer Overflow Attack (AskCypert CLaaS)

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

More information

Machine Level Programming: Basics

Machine Level Programming: Basics Machine Level Programming: Basics Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 2 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed

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

Recitation: Attack Lab

Recitation: Attack Lab 15-213 Recitation: Attack Lab TA 11 Feb 2017 Agenda Reminders Stacks Attack Lab Activities Reminders Bomb lab is due tomorrow (14 Feb, 2017)! But if you wait until the last minute, it only takes a minute!

More information

Machine Level Programming: Basics

Machine Level Programming: Basics Machine Level Programming: Basics Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 2 Instructor: Joanna Klukowska Why do we look at machine code? understanding how the high-level programming

More information

Lecture 4: x86_64 Assembly Language

Lecture 4: x86_64 Assembly Language CSCI-GA.1144-001 PAC II Lecture 4: x86_64 Assembly Language Some slides adapted (and slightly modified) from: Randy Bryant Dave O Hallaron Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com

More information

CS356: Discussion #7 Buffer Overflows. Marco Paolieri

CS356: Discussion #7 Buffer Overflows. Marco Paolieri CS356: Discussion #7 Buffer Overflows Marco Paolieri (paolieri@usc.edu) Array Bounds class Bounds { public static void main(string[] args) { int[] x = new int[10]; for (int i = 0; i

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

CSE 351 Midterm Exam

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

More information

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

x86 64 Programming II

x86 64 Programming II x86 64 Programming II 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

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

x86 64 Programming I CSE 351 Autumn 2017 Instructor: Justin Hsia

x86 64 Programming I CSE 351 Autumn 2017 Instructor: Justin Hsia x86 64 Programming I 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 Administrivia

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

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

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

More information

Question Points Score Total: 100

Question Points Score Total: 100 Computer Science 2021 Spring 2016 Midterm Exam 1 February 29th, 2016 Time Limit: 50 minutes, 3:35pm-4:25pm This exam contains 7 pages (including this cover page) and 5 questions. Once we tell you to start,

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 5

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 5 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 5 LAST TIME Began exploring x86-64 instruction set architecture 16 general-purpose registers Also: All registers are 64 bits wide rax-rdx are

More information

18-600: Recitation #4 Exploits

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

More information

L09: Assembly Programming III. Assembly Programming III. CSE 351 Spring Guest Lecturer: Justin Hsia. Instructor: Ruth Anderson

L09: Assembly Programming III. Assembly Programming III. CSE 351 Spring Guest Lecturer: Justin Hsia. Instructor: Ruth Anderson Assembly Programming III CSE 351 Spring 2017 Guest Lecturer: Justin Hsia Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis

More information

Functions. Ray Seyfarth. August 4, Bit Intel Assembly Language c 2011 Ray Seyfarth

Functions. Ray Seyfarth. August 4, Bit Intel Assembly Language c 2011 Ray Seyfarth Functions Ray Seyfarth August 4, 2011 Functions We will write C compatible function C++ can also call C functions using extern "C" {...} It is generally not sensible to write complete assembly programs

More information

Compiling C Programs Into X86-64 Assembly Programs

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

More information

Changelog. Brief Assembly Refresher. a logistics note. last time

Changelog. Brief Assembly Refresher. a logistics note. last time Changelog Brief Assembly Refresher Changes made in this version not seen in first lecture: 23 Jan 2018: if-to-assembly if (...) goto needed b < 42 23 Jan 2018: caller/callee-saved: correct comment about

More information

Changelog. Assembly (part 1) logistics note: lab due times. last time: C hodgepodge

Changelog. Assembly (part 1) logistics note: lab due times. last time: C hodgepodge Changelog Assembly (part 1) Corrections made in this version not seen in first lecture: 31 August 2017: slide 34: split out from previous slide; clarify zero/positive/negative 31 August 2017: slide 26:

More information

x86-64 Programming II

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

More information

Corrections made in this version not seen in first lecture:

Corrections made in this version not seen in first lecture: Assembly (part 1) 1 Changelog 1 Corrections made in this version not seen in first lecture: 31 August 2017: slide 34: split out from previous slide; clarify zero/positive/negative 31 August 2017: slide

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

More information

Introduction to Compilers and Language Design Copyright (C) 2017 Douglas Thain. All rights reserved.

Introduction to Compilers and Language Design Copyright (C) 2017 Douglas Thain. All rights reserved. Introduction to Compilers and Language Design Copyright (C) 2017 Douglas Thain. All rights reserved. Anyone is free to download and print the PDF edition of this book for personal use. Commercial distribution,

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

CSE 351 Midterm - Winter 2017

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

More information

CSE 401/M501 Compilers

CSE 401/M501 Compilers CSE 401/M501 Compilers x86-64 Lite for Compiler Writers A quick (a) introduction or (b) review [pick one] Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 J-1 Administrivia HW3 due tonight At most 1

More information

Setting & Examining Condition Codes. int gt(long x, long y) { return x > y; } int has_nonzero_masked(long x, long mask) { return!!

Setting & Examining Condition Codes. int gt(long x, long y) { return x > y; } int has_nonzero_masked(long x, long mask) { return!! Setting & Examining Condition Codes int has_nonzero_masked(long x, long mask) urn!!(x & mask); # x in %rdi, y in %rsi, urn value in %eax has_nonzero_masked: xorl %eax, %eax testq %rsi, %rdi setne %al int

More information