DOC PREVIEW
CMU CS 15213 - Recitation

This preview shows page 1-2-3-23-24-25-26-46-47-48 out of 48 pages.

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

Unformatted text preview:

ANITA S SUPER AWESOME RECITATION SLIDES 15 18 213 Introduction to Computer Systems Stacks and Buflab 23 Sept 2013 Anita Zhang WHAT S NEW OR NOT Bomb Lab is due Tuesday tomorrow 11 59 PM Your late days are wasted here Student But if you wait until the last minute then it only takes a minute Buf Lab out Tuesday tomorrow 11 59 PM Not quite true Hacking the stack Stacks will be on the exams They re tough at first but I believe in you SPEAKING OF THE EXAM Midterm Wed 16 Oct Sat 19 Oct 2013 Covers everything up to and including caches Chapters 1 3 and 6 of textbook Up to and including Cache Lab Lectures up to and including Caches 1 Oct 2013 Recitation exam review the week of exam Read each chapter 3 times work the practice problems and do previous exams Do enough midterms until you feel comfortable with the material at least 5 recent ones Depending on the semester caches can be found in Exam 2 TO THOSE WHO WANT A COOL SHELL http www contrib andrew cmu edu anitazha 15213 tips html Scroll down to the part about Shell of Choice Follow the directions Your terminal will look something like this JOURNEY THROUGH TIME Basic Assembly Review Jump Tables vs Sparse Switch Terminology Stacks IA32 Stack Discipline Function Call Overview Stack Walkthrough Extras on x86 64 stacks Buf Lab Quick Start Essential Items of Business Miscellany Demo ASSEMBLY COVERAGE JUMP TABLES Jump tables Think of it as an array of addresses in memory Use jump instructions to execute from these addresses Using assembly it is possible to index into the array Each entry of will hold addresses of instructions JUMP TABLE EXAMPLE The tip off is something like this jmpq 0x400600 rax 8 Empty base means implied 0 rax is the index 8 is the scale 64 bit machine addresses are 8 bytes indicates a dereference like in C notation Like leal does not do a dereference with parenthesis Put it all together Jump to the address stored in the address 0x400600 rax 8 Using GDB example output x 8g 0x400600 0x400600 0x00000000004004d1 0x00000000004004c8 0x400610 0x00000000004004c8 0x00000000004004be 0x400620 0x00000000004004c1 0x00000000004004d7 0x400630 0x00000000004004c8 0x00000000004004be ASSEMBLY COVERAGE SPARSE SWITCH Sparse switch vs jump tables Jump tables work if every entry has a jump location Sparse switches cover cases where there are less densely packed cases Does not make sense to allocate space for 100 entries if only 1 and 100 are used as cases In the following example uses labels to go to the next instruction SPARSE SWITCH EXAMPLE int div111 int x switch x case 0 return 0 movl 8 ebp eax get x cmpl 444 eax x 444 je L8 case 111 return 1 jg L16 case 222 return 2 cmpl 111 eax case 333 return 3 je L5 case 444 return 4 jg L17 case 555 return 5 testl eax eax x 0 case 666 return 6 je L4 case 777 return 7 jmp L14 x 111 L5 movl 1 eax jmp L19 L6 movl 2 eax jmp L19 L7 movl 3 eax jmp L19 case 888 return 8 case 999 return 9 default return 1 L8 movl 4 eax jmp L19 SOME KIND OF STACK MOTIVATION In order to support general recursion a language needs a way to allocate different activation records for different invocations of the same function That way local variables allocated in one recursive call can coexist with local variables allocated in a different call credits to stack overflow DEFINITIONS AND CONVENTIONS Register Some place in hardware that stores bits Caller save Like boxes on the side of memory Saved by the caller of a function Before a function call the caller must save any caller save register values it wants preserved Callee save Saved by the callee of a function The callee is required to save restore values in these registers if it is using these registers in the function ASIDE WHY BOTH Why do we have both caller and callee save Performance Not all registers need to be saved IA32 REGISTERS 6 general purpose registers Caller save eax ecx edx Saved by the caller of a function Callee save ebx edi esi Saved by the callee of a function SPECIAL IA32 REGISTERS Base Pointer ebp Points to the bottom of the stack frame Stack Pointer esp Points to the top of the stack The location of old ebp that gets pushed on entry Usually whatever was last pushed on the stack Instruction Pointer Program Counter eip Points to the next instruction to be executed IA32 TERMINOLOGY Higher addresses ie 0xFFFFFFFF bottom Direction of stack growth esp Lower addresses ie 0x00000000 top ASIDE TECHNOLOGY NOTE AGAIN This class is strictly x86 64 Other architectures may have different conventions May not use stacks at all weird I know Stacks grow down up depending on implementation Very confusing to those new to stacks ASIDE DIRECTION OF GROWTH Stack direction REALLY doesn t matter Direction of growth is dependent on the processor May be selectable for up down Or some other direction BAM CIRCULAR STACK SPARC scalable processor architecture Architecture ASIDE DIRECTION OF GROWTH Examples from StackOverflow x86 down SPARC in a circle System z in a linked list down at least for zLinux ARM selectable PDP11 down WHAT HAPPENS IN IA32 PUSH Pushing on the stack bottom bottom pushl eax 0x15 0x15 esp 0x213 esp In general pushl translates to in AT T syntax subl 0x4 esp movl src esp WHAT HAPPENS IN IA32 POP Popping off the stack bottom bottom popl eax 0x100 esp esp 0x100 0x213 In general popl translates to in AT T syntax movl esp dest addl 0x4 esp STACK FRAMES WHATCHAMACALLITS Every function call gets a stack frame All the useful stuff can go on the stack Local variables scalars arrays structs What the compiler couldn t fit into registers Callee caller save registers Temporary variables Arguments Stacks can make recursion work Key idea Storage for each instance of procedure call stolen out of 15 410 slides SO THAT S WHAT IT LOOKS LIKE Increasing Addresses Earlier Frames Argument n Caller s frame Argument 1 Return Address Frame Pointer ebp Saved old ebp Saved registers local variables and temporaries Argument build area Stack Pointer esp Current callee frame ROLES OF A FUNCTION CALLER Caller Save push relevant caller save registers Push arguments Call function Caller after function return Remove add to esp or pop arguments Restore pop saved caller save registers ROLES OF A FUNCTION CALLEE Callee Push ebp save stack frame Copy move esp into ebp Save push callee save registers it wants to use Callee before return Restore pop callee save registers previously saved Copy move ebp into esp Moves stack pointer to the saved ebp Restore pop ebp FUNCTION CALLS OTHER OPERATIONS Implied operations


View Full Document

CMU CS 15213 - Recitation

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

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