DOC PREVIEW
CMU CS 15213 - Lecture

This preview shows page 1-2-3-4-27-28-29-30-55-56-57-58 out of 58 pages.

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

Unformatted text preview:

15 213 The course that gives CMU its Zip Machine Level Programming III Procedures Sept 15 2006 IA32 x86 64 stack discipline Register saving conventions Creating pointers to local variables class06 ppt Argument passing in registers Minimizing stack usage Using stack pointer as only reference 15 213 F 06 IA32 Stack Region of memory managed with stack discipline Grows toward lower addresses Register esp indicates lowest stack address Stack Bottom Increasing Addresses z address of top element Stack Pointer esp Stack Grows Down Stack Top 2 15 213 F 06 IA32 Stack Pushing Pushing pushl Src Fetch operand at Src Decrement esp by 4 Stack Bottom Increasing Addresses Write operand at address given by esp Stack Pointer esp Stack Grows Down 4 Stack Top 3 15 213 F 06 IA32 Stack Popping Popping popl Dest Read operand at address given by esp Increment esp by 4 Write to Dest Stack Bottom Increasing Addresses Stack Pointer esp Stack Grows Down 4 Stack Top 4 15 213 F 06 Procedure Control Flow Use stack to support procedure call and return Procedure call call label Push return address on stack Jump to label Return address value Address of instruction beyond call Example from disassembly 804854e e8 3d 06 00 00 call 8048b90 main 8048553 50 pushl eax z Return address 0x8048553 Procedure return 5 ret Pop address from stack Jump to address 15 213 F 06 Procedure Call Example 804854e 8048553 e8 3d 06 00 00 50 call 0x110 0x110 0x10c 0x10c 0x108 0x108 123 call pushl 8048b90 main eax 8048b90 123 0x104 0x8048553 esp esp 0x108 eip 0x804854e 0x108 0x104 eip 0x8048b90 0x804854e eip is program counter 6 15 213 F 06 Procedure Return Example 8048591 c3 ret ret 0x110 0x110 0x10c 0x10c 0x108 123 0x108 0x104 0x8048553 esp 0x104 eip 0x8048591 123 0x8048553 esp 0x104 0x108 eip 0x8048553 0x8048591 eip is program counter 7 15 213 F 06 Stack Based Languages Languages that Support Recursion e g C Pascal Java Code must be Reentrant z Multiple simultaneous instantiations of single procedure Need some place to store state of each instantiation z Arguments z Local variables z Return pointer Stack Discipline State for given procedure needed for limited time z From when called to when return Callee returns before caller does Stack Allocated in Frames 8 state for single procedure instantiation 15 213 F 06 Call Chain Example Code Structure yoo who 9 Call Chain yoo who amI amI Procedure amI recursive who amI amI amI amI amI amI 15 213 F 06 Stack Frames Contents Local variables Return information Temporary space yoo who amI Management Space allocated when enter procedure z Set up code Deallocated when return z Finish code Pointers 10 Stack pointer esp indicates stack top Frame pointer ebp indicates start of current frame Frame Pointer ebp proc Stack Pointer esp Stack Top 15 213 F 06 Stack Operation yoo who 11 Call Chain yoo Frame Pointer ebp yoo Stack Pointer esp 15 213 F 06 Stack Operation who amI amI 12 Call Chain yoo Frame Pointer ebp yoo who who Stack Pointer esp 15 213 F 06 Stack Operation amI amI 13 Call Chain yoo yoo who amI Frame Pointer ebp who amI Stack Pointer esp 15 213 F 06 Stack Operation amI amI Call Chain yoo yoo who who amI amI Frame Pointer ebp amI amI Stack Pointer esp 14 15 213 F 06 Stack Operation amI amI Call Chain yoo yoo who who amI amI amI amI Frame Pointer ebp amI amI Stack Pointer esp 15 15 213 F 06 Stack Operation amI amI Call Chain yoo yoo who who amI amI Frame Pointer ebp amI amI amI 16 Stack Pointer esp 15 213 F 06 Stack Operation amI amI Call Chain yoo yoo who amI amI Frame Pointer ebp who amI Stack Pointer esp amI 17 15 213 F 06 Stack Operation who amI amI Call Chain yoo Frame Pointer ebp yoo who who amI Stack Pointer esp amI amI 18 15 213 F 06 Stack Operation amI Call Chain yoo yoo Frame Pointer ebp who amI amI amI who amI Stack Pointer esp amI 19 15 213 F 06 Stack Operation who amI amI Call Chain Frame Pointer ebp yoo yoo who who amI amI Stack Pointer esp amI amI 20 15 213 F 06 Stack Operation Call Chain yoo who Frame Pointer ebp yoo Stack Pointer esp yoo who amI amI amI amI 21 15 213 F 06 IA32 Linux Stack Frame Current Stack Frame Top to Bottom Parameters for function about to call Caller Frame z Argument build Local variables z If can t keep in registers Saved register context Old frame pointer Arguments Frame Pointer ebp Saved Registers Local Variables Caller Stack Frame Return address z Pushed by call instruction 22 Arguments for this call Return Addr Old ebp Stack Pointer esp Argument Build 15 213 F 06 Revisiting swap Calling swap from call swap int zip1 15213 int zip2 91125 void call swap swap zip1 zip2 void swap int xp int yp int t0 xp int t1 yp xp t1 yp t0 23 call swap pushl zip2 pushl zip1 call swap Global Var Global Var Resulting Stack zip2 zip1 Rtn adr esp 15 213 F 06 Revisiting swap void swap int xp int yp int t0 xp int t1 yp xp t1 yp t0 swap pushl ebp movl esp ebp pushl ebx movl movl movl movl movl movl Set Up 12 ebp ecx 8 ebp edx ecx eax edx ebx eax edx ebx ecx movl 4 ebp ebx movl ebp esp popl ebp ret 24 Body Finish 15 213 F 06 swap Setup 1 Resulting Stack Entering Stack ebp ebp zip2 yp zip1 xp Rtn adr esp Rtn adr Old ebp esp swap pushl ebp movl esp ebp pushl ebx 25 15 213 F 06 swap Setup 2 Resulting Stack Entering Stack ebp zip2 yp zip1 xp Rtn adr esp Rtn adr Old ebp ebp esp swap pushl ebp movl esp ebp pushl ebx 26 15 213 F 06 swap Setup 3 Resulting Stack Entering Stack ebp zip2 yp zip1 xp Rtn adr esp Rtn adr Old ebp ebp Old ebx esp swap pushl ebp movl esp ebp pushl ebx 27 15 213 F 06 Effect of swap Setup Entering Stack Resulting Stack ebp Offset relative to ebp zip2 12 yp zip1 8 xp 4 Rtn adr Rtn adr esp movl 12 ebp ecx get yp movl 8 ebp edx get xp 28 0 Old ebp ebp Old ebx esp Body 15 213 F 06 swap Finish 1 swap s Stack Offset Offset 12 yp 12 yp 8 xp 8 xp 4 Rtn adr 4 Rtn adr 0 Old ebp ebp 0 Old ebp ebp 4 Old ebx esp 4 Old ebx esp Observation 29 Saved restored register ebx movl 4 ebp ebx movl ebp esp popl ebp ret 15 213 F 06 swap Finish 2 swap s Stack Offset swap s Stack Offset 12 yp 12 yp 8 xp 8 xp 4 Rtn adr 4 Rtn adr 0 Old ebp ebp 4 Old ebx esp 0 Old ebp ebp esp movl 4 ebp ebx movl ebp esp popl ebp …


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

52 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

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?