DOC PREVIEW
CMU CS 15213 - Recitation

This preview shows page 1-2-24-25 out of 25 pages.

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

Unformatted text preview:

15213 Recitation Section C Shimin Chen Sept 16 2002 Outline Assembly Review C ASM using GDB ASM C Assembly Review Machine Model CPU E I P Registers Condition Codes Addresses Data Instructions Memory Object Code Program Data Stack 15213 Recitation C 2 Shimin Chen Assembly Format Op Src Dest add eax ebx sub eax ebx ebx eax ebx eax Op Arg jmp 0x87654321 jge 0x87654321 15213 Recitation C unconditional branch branch if in signed comparison 3 Shimin Chen Memory Addressing Mode Generic form D R1 R2 S Address Reg R1 Reg R2 S D e g 0x8 eax ebx 0x4 the address is eax ebx 0x4 0x8 Special forms omit D R1 R2 or S R1 D R1 R1 R2 D R1 R2 15213 Recitation C 4 Shimin Chen Exercise What do the ASM mean 1 2 3 4 5 6 sub ecx edx cmp ecx 0x4 jge 0x12345678 mov ebx eax mov ebx esi 0x4 edi lea ebx esi 0x4 edi xor ecx ecx 15213 Recitation C 5 Shimin Chen Procedure Related Instructions int a func int arg1 int arg2 int arg3 Get arguments arg1 mov 8 ebp ecx arg2 mov 12 ebp ecx arg3 mov 16 ebp ecx Set return value mov 0x1 eax 15213 Recitation C return 1 6 Shimin Chen C ASM Compilation and GDB basics C ASM Examples 15213 Recitation C 7 Shimin Chen Compiling and Debugging C Code Generating ASM with gcc gcc O S Wall example c generate example s Debugging C code gcc O g o example Wall example c gdb example 15213 Recitation C 8 Shimin Chen What if compiling without g gcc O o example Wall example c gdb will not know the C code for assembly the same as in L2 bomb lab use gdb to examine the object code Other tools objdump etc see L2 description 15213 Recitation C 9 Shimin Chen Example func1 int func1 int a int b int x y x a b y 2 x b return x y 15213 Recitation C 10 Shimin Chen ASM of func1 Dump of assembler code for function func1 0x8048420 func1 push ebp 0x8048421 func1 1 mov esp ebp 0x8048423 func1 3 mov 0xc ebp eax 0x8048426 func1 6 mov 0x8 ebp ecx 0x8048429 func1 9 add eax ecx 0x804842b func1 11 lea ecx ecx 1 edx 0x804842e func1 14 sub eax edx 0x8048430 func1 16 mov ecx eax 0x8048432 func1 18 imul edx eax 0x8048435 func1 21 mov ebp esp 0x8048437 func1 23 pop ebp 0x8048438 func1 24 ret 0x8048439 func1 25 lea 0x0 esi esi End of assembler dump 15213 Recitation C 11 Shimin Chen ASM of func1 Dump of assembler code for function func1 0x8048420 func1 push ebp 0x8048421 func1 1 mov esp ebp 0x8048423 func1 3 mov 0xc ebp eax 0x8048426 func1 6 mov 0x8 ebp ecx 0x8048429 func1 9 add eax ecx 0x804842b func1 11 lea ecx ecx 1 edx 0x804842e func1 14 sub eax edx 0x8048430 func1 16 mov ecx eax 0x8048432 func1 18 imul edx eax 0x8048435 func1 21 mov ebp esp 0x8048437 func1 23 pop ebp 0x8048438 func1 24 ret 0x8048439 func1 25 lea 0x0 esi esi End of assembler dump 15213 Recitation C 12 eax b ecx a ecx a b edx 2 ecx edx b eax x return x y Shimin Chen Using GDB to run the program Let s use gdb to run the program and examine registers and memory locations break func1 run p x ebp x 2wx ebp 8 15213 Recitation C 13 Shimin Chen Example 2 int func2 int a int b if a b return a else return b 15213 Recitation C 14 Shimin Chen ASM of func2 Dump of assembler code for function func2 0x804843c func2 push ebp 0x804843d func2 1 mov esp ebp 0x804843f func2 3 mov 0x8 ebp edx 0x8048442 func2 6 mov 0xc ebp eax 0x8048445 func2 9 cmp eax edx 0x8048447 func2 11 jle 0x804844b func2 15 0x8048449 func2 13 mov edx eax 0x804844b func2 15 mov ebp esp 0x804844d func2 17 pop ebp 0x804844e func2 18 ret 0x804844f func2 19 nop End of assembler dump 15213 Recitation C 15 Shimin Chen ASM of func2 Dump of assembler code for function func2 0x804843c func2 push ebp 0x804843d func2 1 mov esp ebp 0x804843f func2 3 mov 0x8 ebp edx edx a 0x8048442 func2 6 mov 0xc ebp eax eax b 0x8048445 func2 9 cmp eax edx edx eax 0x8048447 func2 11 jle 0x804844b func2 15 0x8048449 func2 13 mov edx eax eax a 0x804844b func2 15 mov ebp esp 0x804844d func2 17 pop ebp 0x804844e func2 18 ret 0x804844f func2 19 nop End of assembler dump 15213 Recitation C 16 Shimin Chen Example 3 int func3 int a int b int r 0xDEADBEEF switch a case 0 case 1 r b break case 2 r a b break case 3 r a b break case 4 r a b break default return r 15213 Recitation C 17 Shimin Chen ASM of func3 Dump of assembler code for function func3 0x8048450 func3 push ebp 0x8048451 func3 1 mov esp ebp 0x8048453 func3 3 mov 0x8 ebp edx 0x8048456 func3 6 mov 0xc ebp ecx 0x8048459 func3 9 mov 0xdeadbeef eax 0x804845e func3 14 cmp 0x4 edx 0x8048461 func3 17 ja 0x804848b func3 59 0x8048463 func3 19 jmp 0x8048598 edx 4 0x804846a func3 26 lea 0x0 esi esi 0x8048470 func3 32 mov ecx eax 0x8048472 func3 34 jmp 0x804848b func3 59 0x8048474 func3 36 lea ecx edx 1 eax 0x8048477 func3 39 jmp 0x804848b func3 59 15213 Recitation C 18 Shimin Chen ASM of func3 0x8048479 func3 41 0x8048480 func3 48 0x8048482 func3 50 0x8048484 func3 52 0x8048486 func3 54 0x8048488 func3 56 0x804848b func3 59 0x804848d func3 61 0x804848e func3 62 lea mov sub jmp mov imul mov pop ret 0x0 esi 1 esi edx eax ecx eax 0x804848b func3 59 edx eax ecx eax ebp esp ebp gdb x 5wx 0x8048598 0x8048598 IO stdin used 4 0x08048470 0x08048474 0x08048480 0x80485a8 IO stdin used 20 0x08048486 15213 Recitation C 19 0x08048470 Shimin Chen ASM of func3 Dump of assembler code for function func3 0x8048450 func3 push ebp 0x8048451 func3 1 mov esp ebp 0x8048453 func3 3 mov 0x8 ebp edx 0x8048456 func3 6 mov 0xc ebp ecx 0x8048459 func3 9 mov 0xdeadbeef eax 0x804845e func3 14 cmp 0x4 edx 0x8048461 func3 17 ja 0x804848b func3 59 0x8048463 func3 19 jmp 0x8048598 edx 4 0x804846a func3 26 lea 0x0 esi esi 0x8048470 func3 32 mov ecx eax 0x8048472 func3 34 jmp 0x804848b func3 59 0x8048474 func3 36 lea ecx edx 1 eax 0x8048477 func3 39 jmp 0x804848b func3 59 15213 Recitation C 20 edx a ecx b eax is r a 4 jmp table nop r b r a b Shimin Chen ASM of func3 0x8048479 func3 41 0x8048480 func3 48 0x8048482 func3 50 0x8048484 func3 52 0x8048486 func3 54 0x8048488 func3 56 0x804848b func3 59 0x804848d func3 61 0x804848e func3 62 lea mov sub jmp mov imul mov pop ret 0x0 esi 1 esi edx eax ecx eax 0x804848b func3 59 edx eax ecx eax ebp esp ebp gdb x 5wx 0x8048598 0x8048598 IO stdin used 4 0x08048470 0x08048474 …


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?