DOC PREVIEW
CMU CS 15213 - Example Structured Data And Stack Problems

This preview shows page 1-2-3-4-5 out of 14 pages.

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

Unformatted text preview:

Example Structured Data And Stack Problems Problem 1 Consider the following source code and corresponding assembly include stdio h char read char char c scanf s c return c int main printf c n read char 080484c0 read char 80484c0 55 80484c1 89 e5 80484c3 83 ec 80484c6 8d 45 80484c9 50 80484ca 68 98 80484cf e8 6c 80484d4 0f be 80484d8 89 ec 80484da 5d 80484db c3 80484dc 8d 74 080484e0 main 80484e0 55 80484e1 89 80484e3 83 80484e6 83 80484e9 83 80484ec e8 80484f1 83 80484f4 0f 80484f7 50 80484f8 68 80484fd e8 8048502 89 8048504 5d 8048505 c3 e5 ec e4 ec cf c4 be 10 ff 85 04 08 fe ff ff 45 ff 26 00 08 f0 10 ff ff ff 08 c0 9b 85 04 08 6e fe ff ff ec push mov sub lea push push call movsbl mov pop ret lea ebp esp ebp 0x10 esp 0xffffffff ebp eax eax 0x8048598 8048340 init 0x38 0xffffffff ebp eax ebp esp ebp push mov sub and sub call add movsbl push push call mov pop ret ebp esp ebp 0x8 esp 0xfffffff0 esp 0x10 esp 80484c0 read char 0x8 esp al eax eax 0x804859b 8048370 init 0x68 ebp esp ebp Page 1 of 14 0x0 esi 1 esi When the program is executed a breakpoint is placed at the address 0x080484d4 The user inputs the single character a ASCII value 0x61 Assume that when the program is run the value of esp immediately before the first instruction of main 0x080484e0 is executed is 0xbffff6ec Assume that the entire stack space was initialized to zeroes before the program began executing and main is the first function to execute Fill in the following table with the values observed to be on the stack when the program halts at the breakpoint Clearly indicate with labeled arrows what the observed values of the registers ebp and esp would be If the exact hexadecimal value cannot be determined from the information provided but the value has a meaning ie return address saved ebp write the meaning Your answers should be the 4 byte hexadecimal values at the stack location remember this is a little endian machine You do not need to write out all 8 digits of the hexadecimal number zero Address Hex Value 0xbffff6ec 0xbffff6e8 0xbffff6e4 0xbffff6e0 0xbffff6dc 0xbffff6d8 0xbffff6d4 0xbffff6d0 0xbffff6cc 0xbffff6c8 0xbffff6c4 0xbffff6c0 0xbffff6bc 0xbffff6b8 0xbffff6b4 0xbffff6b0 0xbffff6ac 0xbffff6a8 0xbffff6a4 0xbffff6a0 Page 2 of 14 If we continue executing the program with the user having entered a will we successfully return from the function read char If we continue executing the program with the user having entered a will we successfully return from the function main Suppose the user had input the string This is a very long string Would we successfully return from the function read char Suppose the user had input the string This is a very long string Would we successfully return from the function main Page 3 of 14 Problem 2 Consider the source code below where M and N are constants declared with define int array1 M N int array2 N M int copy int i int j array1 i j array2 j i Suppose the above code generates the following assembly code copy pushl movl pushl movl movl leal leal leal subl addl movl movl popl popl ret ebp esp ebp ebx 8 ebp ecx 12 ebp edx ecx ecx 2 ebx edx ebx 2 ebx 0 edx 8 eax edx eax ecx eax array2 eax 4 eax eax array1 ebx 4 ebx ebp What are the values of M and N M N Page 4 of 14 Problem 3 onsider the following C declarations typedef struct short prime short rib char raw 3 long filet cow typedef struct short prime long rib char raw 5 short roast long filet bull A Using the templates below allowing a maximum of 24 bytes indicate the allocation of data for structs of type cow and bull Mark off and label the areas for each individual element arrays may be labeled as a single element Cross hatch the parts that are allocated but not used to satisfy alignment Assume the Linux alignment rules discussed in class Clearly indicate the right hand boundary of the data structure with a vertical line cow 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 bull 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Page 5 of 14 B Now consider the following C code fragment void foo cow oldcow bull newcow this zeros out all the space allocated for oldcow bzero void oldcow sizeof cow oldcow prime 0xabcd oldcow rib 0x1234 oldcow raw 0 0x01 oldcow raw 1 0x30 oldcow raw 2 0x79 oldcow raw 3 0xff oldcow filet 0x66778855 newcow bull oldcow Once this code has run we begin to access the elements of newcow Below give the value of each element of newcow that is listed Assume that this code is run on a Little Endian machine such as a Linux x86 machine You must give your answer in hexadecimal format Be careful about byte ordering a newcow prime 0x b newcow rib 0x c newcow raw 0 0x d newcow raw 3 0x e newcow raw 5 0x Page 6 of 14 Problem 4 This problem concerns the following C code This program reads a string on standard input and prints an integer in hexadecimal format based on the input string it read include stdio h Read a string from stdin into buf short read string short buf 3 scanf s char buf return buf 3 int main printf 0x x n read string Here is the corresponding machine code on a Linux x86 machine 08048414 read string 8048414 55 8048415 89 e5 8048417 83 ec 18 804841a 83 c4 f8 804841d 8d 45 f8 8048420 50 8048421 68 b8 84 8048426 e8 e1 fe 804842b 0f bf 45 804842f 89 ec 8048431 5d 8048432 c3 8048433 90 08048434 main 8048434 55 8048435 89 e5 8048437 83 ec 08 804843a 83 c4 f8 804843d e8 d2 ff 8048442 98 8048443 50 8048444 68 bb 84 8048449 e8 ee fe 804844e 89 ec 8048450 5d 8048451 c3 04 08 ff ff fe ff ff 04 08 ff ff push mov sub add lea push push call movswl mov pop ret nop ebp esp ebp 0x18 esp 0xfffffff8 esp 0xfffffff8 ebp eax eax 0x80484b8 804830c init 0x50 0xfffffffe ebp eax ebp esp ebp push mov sub add call cwtl push push call mov pop ret ebp esp ebp 0x8 esp 0xfffffff8 esp 8048414 read string Page 7 of 14 eax 0x80484bb 804833c init 0x80 ebp esp ebp This problem tests your understanding of the stack discipline and byte ordering Here are some notes to help you work the problem scanf s buf reads an input string from the standard input stream stdin and stores it at address buf including the terminating 0 character It does not check the size of the destination buffer printf 0x …


View Full Document

CMU CS 15213 - Example Structured Data And Stack Problems

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 Example Structured Data And Stack Problems
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 Example Structured Data And Stack Problems 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 Example Structured Data And Stack Problems 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?