DOC PREVIEW
CMU CS 15213 - lecture

This preview shows page 1-2-3-4-5-35-36-37-38-39-71-72-73-74-75 out of 75 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 75 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 7th Lecture Feb 3rd Instructors Gregory Kesden and Markus P schel Carnegie Mellon Last Time Complete memory addressing mode eax 17 eax 2 ebx ecx 8 Arithmetic operations subl eax ecx sall 4 edx addl 16 ebp ecx ecx ecx eax edx edx 4 ecx ecx Mem 16 ebp leal 4 edx eax eax imull ecx eax eax 4 edx eax eax eax ecx Carnegie Mellon Last Time x86 64 vs IA32 Integer registers 16 x 64 bit vs 8 x 32 bit movq addq vs movl addl Better support for passing function arguments in registers rax eax r8 r8d rbx edx r9 r9d rcx ecx r10 r10d rdx ebx r11 r11d rsi esi r12 r12d rdi edi r13 r13d rsp esp r14 r14d rbp ebp r15 r15d Control Condition code registers Set as side effect or by cmp test Used CF ZF Read out by setx instructions setg setle Or by conditional jumps jle L4 je L10 SF OF Carnegie Mellon Last Time Do While loop Goto Version C Code do Body while Test loop Body if Test goto loop While Do loop Do While Version While version while Test Body if Test goto done do Body while Test done or Goto Version if Test goto done loop Body if Test goto loop done goto middle loop Body middle if Test goto loop Carnegie Mellon Today For loops Switch statements Procedures Carnegie Mellon For Loop Example Square and Multiply Compute x raised to nonnegative power p int ipwr for int x unsigned p int result for result 1 p 0 p p 1 if p 0x1 result x x x x return result Algorithm Exploit bit representation p p0 2p1 22p2 2n 1pn 1 Gives xp z0 z1 2 z2 2 2 zn 12 2 2 Example zi 1 when pi 0 zi x when pi 1 Complexity O log p n 1 times 310 32 38 32 32 2 2 Carnegie Mellon ipwr Computation Compute x raised to nonnegative power p int ipwr for int x unsigned p int result for result 1 p 0 p p 1 if p 0x1 result x x x x return result before iteration result x 3 p 10 1 2 3 4 5 1 1 9 9 59049 3 9 81 6561 43046721 10 10102 5 1012 2 102 1 12 0 Carnegie Mellon For Loop Example int result for result 1 p 0 p p 1 if p 0x1 result x x x x General Form for Init Test Update Body Test p 0 Init result 1 Update p p 1 Body if p 0x1 result x x x x Carnegie Mellon For While Do While For Version for Init Test Update Body Goto Version Init if Test goto done loop Body Update if Test goto loop done While Version Init while Test Body Update Do While Version Init if Test goto done do Body Update while Test done Carnegie Mellon For Loop Compilation 1 For Version for Init Test Update Body Goto Version Init if Test goto done loop Body Update if Test goto loop done for result 1 p 0 p p 1 if p 0x1 result x x x x result 1 if p 0 goto done loop if p 0x1 result x x x x p p 1 if p 0 goto loop done Carnegie Mellon For While Jump to Middle For Version for Init Test Update Body While Version Init while Test Body Update Goto Version Init goto middle loop Body Update middle if Test goto loop done Carnegie Mellon For Loop Compilation 2 For Version for Init Test Update Body Goto Version Init goto middle loop Body Update middle if Test goto loop done for result 1 p 0 p p 1 if p 0x1 result x x x x result 1 goto middle loop if p 0x1 result x x x x p p 1 middle if p 0 goto loop done Carnegie Mellon Today For loops Switch statements Procedures Carnegie Mellon long switch eg long x long y long z long w 1 switch x case 1 w y z break case 2 w y z Fall Through case 3 w z break case 5 case 6 w z break default w 2 return w Switch Statement Example Multiple case labels Here 5 6 Fall through cases Here 2 Missing cases Here 4 Carnegie Mellon Jump Table Structure switch x case val 0 Block 0 case val 1 Block 1 case val n 1 Block n 1 Jump Targets Jump Table Switch Form jtab Targ0 Targ0 Targ1 Targ2 Targn 1 Targ1 Targ2 Code Block 0 Code Block 1 Code Block 2 Approximate Translation target JTab x goto target Targn 1 Code Block n 1 Carnegie Mellon Switch Statement Example IA32 long switch eg long x long y long z long w 1 switch x return w Setup switch eg pushl ebp movl esp ebp pushl ebx movl 1 ebx movl 8 ebp edx movl 16 ebp ecx cmpl 6 edx ja L61 jmp L62 edx 4 Setup Setup Setup w 1 edx x ecx z Will disappear x 6 Blackboard if goto default goto JTab x Carnegie Mellon Switch Statement Example IA32 long switch eg long x long y long z long w 1 switch x return w Setup Indirect jump switch eg pushl ebp movl esp ebp pushl ebx movl 1 ebx movl 8 ebp edx movl 16 ebp ecx cmpl 6 edx ja L61 jmp L62 edx 4 Jump table section rodata align 4 L62 long L61 long L56 long L57 long L58 long L61 long L60 long L60 Setup Setup Setup w 1 edx x ecx z x 6 if goto default goto JTab x x x x x x x x 0 1 2 3 4 5 6 Carnegie Mellon Assembly Setup Explanation Table Structure Each target requires 4 bytes Base address at L62 Jumping Direct jmp L61 Jump target is denoted by label L61 Jump table section rodata align 4 L62 long L61 long L56 long L57 long L58 long L61 long L60 long L60 Indirect jmp L62 edx 4 Start of jump table L62 Must scale by factor of 4 labels have 32 bit 4 Bytes on IA32 Fetch target from effective Address L61 edx 4 Only for 0 x 6 x x x x x x x 0 1 2 3 4 5 6 Carnegie Mellon Jump Table 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 switch x case 1 L56 w y z break case 2 L57 w y z Fall Through case 3 L58 w z break case 5 case 6 L60 w z break default L61 w 2 Carnegie Mellon Code Blocks Partial switch x case 2 L57 w y z Fall Through case 3 L58 w z break default L61 w 2 L61 Default case movl 2 ebx w 2 movl ebx eax Return w popl ebx leave ret L57 Case 2 …


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

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