DOC PREVIEW
CMU CS 15213 - Lecture

This preview shows page 1-2-3-25-26-27-28-50-51-52 out of 52 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Carnegie Mellon Introduction to Computer Systems 15 213 18 243 spring 2009 8th Lecture Feb 5th Instructors Gregory Kesden and Markus P schel Carnegie Mellon Last Time For loops for loop while loop do while loop goto version for loop while loop goto jump to middle version Switch statements Jump tables jmp L62 edx 4 Decision trees not shown Jump table section rodata align 4 L62 long L61 long L56 long L57 long L58 long L61 long L60 long L60 x x x x x x x 0 1 2 3 4 5 6 Carnegie Mellon Last Time Procedures IA32 call return esp ebp local variables recursive functions Caller Frame Arguments eax Caller Save ebp edx Saved Registers Local Variables ecx ebx Callee Save esi edi Special esp ebp Return Addr Old ebp esp Argument Build Carnegie Mellon Today Procedures x86 64 Arrays One dimensional Multi dimensional nested Multi level Structures Carnegie Mellon x86 64 Integer Registers rax eax r8 r8d rbx ebx r9 r9d rcx ecx r10 r10d rdx edx r11 r11d rsi esi r12 r12d rdi edi r13 r13d rsp esp r14 r14d rbp ebp r15 r15d Twice the number of registers Accessible as 8 16 32 64 bits Carnegie Mellon x86 64 Integer Registers rax Return value r8 Argument 5 rbx Callee saved r9 Argument 6 rcx Argument 4 r10 Callee saved rdx Argument 3 r11 Used for linking rsi Argument 2 r12 C Callee saved rdi Argument 1 r13 Callee saved rsp Stack pointer r14 Callee saved rbp Callee saved r15 Callee saved Carnegie Mellon x86 64 Registers Arguments passed to functions via registers If more than 6 integral parameters then pass rest on stack These registers can be used as caller saved as well All references to stack frame via stack pointer Eliminates need to update ebp rbp Other Registers 6 1 callee saved 2 or 3 have special uses Carnegie Mellon x86 64 Long Swap void swap long xp long yp long t0 xp long t1 yp xp t1 yp t0 swap movq movq movq movq ret Operands passed in registers First xp in rdi second yp in rsi 64 bit pointers No stack operations required except ret Avoiding stack Can hold all local information in registers rdi rdx rsi rax rax rdi rdx rsi Carnegie Mellon x86 64 Locals in the Red Zone Swap using local array void swap a long xp long yp volatile long loc 2 loc 0 xp loc 1 yp xp loc 1 yp loc 0 swap a movq movq movq movq movq movq movq movq ret Avoiding Stack Pointer Change Can hold all information within small window beyond stack pointer rdi rax rax 24 rsp rsi rax rax 16 rsp 16 rsp rax rax rdi 24 rsp rax rax rsi rtn Ptr 8 unused 16 loc 1 24 loc 0 rsp Carnegie Mellon x86 64 NonLeaf without Stack Frame long scount 0 Swap a i a i 1 void swap ele se long a int i swap a i a i 1 scount No values held while swap being invoked No callee save registers needed swap ele se movslq esi rsi Sign extend i leaq rdi rsi 8 rdi a i leaq 8 rdi rsi a i 1 call swap swap incq scount rip scount ret Carnegie Mellon x86 64 Call using Jump long scount 0 Swap a i a i 1 void swap ele long a int i swap a i a i 1 swap ele movslq esi rsi Sign extend i disappear leaq rdi rsi 8 rdi Will a i leaq 8 rdi rsi a i 1 Blackboard jmp swap swap Carnegie Mellon x86 64 Call using Jump long scount 0 Swap a i a i 1 void swap ele long a int i swap a i a i 1 When swap executes ret it will return from swap ele Possible since swap is a tail call no instructions afterwards swap ele movslq esi rsi Sign extend i leaq rdi rsi 8 rdi a i leaq 8 rdi rsi a i 1 jmp swap swap Carnegie Mellon x86 64 Stack Frame Example long sum 0 Swap a i a i 1 void swap ele su long a int i swap a i a i 1 sum a i Keeps values of a and i in callee save registers Must set up stack frame to save these registers swap ele su movq rbx 16 rsp movslq esi rbx movq r12 8 rsp movq rdi r12 leaq rdi rbx 8 rdi subq 16 rsp leaq 8 rdi rsi call swap movq r12 rbx 8 rax addq rax sum rip movq rsp rbx movq 8 rsp r12 addq 16 rsp ret Blackboard Carnegie Mellon Understanding x86 64 Stack Frame swap ele su movq rbx 16 rsp movslq esi rbx movq r12 8 rsp movq rdi r12 leaq rdi rbx 8 rdi subq 16 rsp leaq 8 rdi rsi call swap movq r12 rbx 8 rax addq rax sum rip movq rsp rbx movq 8 rsp r12 addq 16 rsp ret Save rbx Extend save i Save r12 Save a a i Allocate stack frame a i 1 swap a i sum a i Restore rbx Restore r12 Deallocate stack frame Carnegie Mellon Understanding x86 64 Stack Frame swap ele su movq rbx 16 rsp movslq esi rbx movq r12 8 rsp movq rdi r12 leaq rdi rbx 8 rdi subq 16 rsp leaq 8 rdi rsi call swap movq r12 rbx 8 rax addq rax sum rip movq rsp rbx movq 8 rsp r12 addq 16 rsp ret Save rbx rsp rtn addr Extend save i 8 r12 Save r12 16 rbx Save a a i Allocate stack frame a i 1 rtn addr swap 8 r12 a i sum a i rsp rbx Restore rbx Restore r12 Deallocate stack frame Carnegie Mellon Interesting Features of Stack Frame Allocate entire frame at once All stack accesses can be relative to rsp Do by decrementing stack pointer Can delay allocation since safe to temporarily use red zone Simple deallocation Increment stack pointer No base frame pointer needed Carnegie Mellon x86 64 Procedure Summary Heavy use of registers Parameter passing More temporaries since more registers Minimal use of stack Sometimes none Allocate deallocate entire block Many tricky optimizations What kind of stack frame to use Calling with jump Various allocation techniques Carnegie Mellon Today Procedures x86 64 Arrays One dimensional Multi dimensional nested Multi level Structures Carnegie Mellon Basic Data Types Integral Stored operated on in general integer registers Signed vs unsigned depends on instructions used Intel GAS Bytes C byte b 1 unsigned char word w 2 unsigned short double word l 4 unsigned int quad word q 8 unsigned long int x86 64 Floating Point Stored operated on in floating point registers Intel GAS Single s Double Extended Bytes C 4 float l 8 double t 10 12 16 long double Carnegie Mellon Array Allocation Basic Principle T A L Array of data type T and length L Contiguously allocated region of L sizeof T bytes char string 12 x x 12 int val 5 x x 4 x 8 x 12 x 16 x 20 double a 3 …


View Full Document

CMU CS 15213 - Lecture

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class17

class17

37 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

45 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

30 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

Linking

Linking

33 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

48 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?