DOC PREVIEW
CMU CS 15213 - Exam

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

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

Unformatted text preview:

Andrew login ID:Full Name:Recitation Section:CS 15-213, Spring 2009Exam 1Tues., February 24, 2009Instructions:• Make sure that your exam is not missing any sheets, then write your full name, Andrew login ID, andrecitation section (A–J) on the front.• Write your answers in the space provided for the problem. If you make a mess, clearly indicate yourfinal answer.• The exam has a maximum score of 100 points.• The problems are of varying difficulty. The point value of each problem is indicated. Pile up the easypoints quickly and then come back to the harder problems.• This exam is OPEN BOOK. You may use any books or notes you like. No calculators or otherelectronic devices are allowed.• Good luck!1 (16):2 (22):3 (13):4 (13):5 (22):6 (14):TOTAL (100):Page 1 of 17Problem 1. (16 points):Consider a new floating point format that follows the IEEE spec you should be familiar, except with 3exponent bits and 2 fraction bits (and 1 sign bit). Fill in all blank cells in the table below. If, in the processof converting a decimal number to a float, you have to round, write the rounded value next to the originaldecimal as well.Description Decimal Binary RepresentationBias -----Smallest positive numberLowest finiteSmallest positive normalized----- −616-----64----- 1 010 10----- 11Page 2 of 17Problem 2. (22 points):Consider the C code written below and compiled on a 32-bit Linux system using GCC.struct s1{int y;short x;};struct s2{struct s1 a;struct s1*b;int x;char c;int y;char e[5];int z;};short fun1(struct s2*s){return s->a.x;}void*fun2(struct s2*s){return &s->z;}int fun3(struct s2*s){return s->z;}short fun4(struct s2*s){return s->b->x;}Page 3 of 17a) What is the size of struct s2?b) How many bytes are wasted for padding?You may use the rest of the space on this page for scratch space to help with the rest of this problem.Nothing written below this line will be graded.Page 4 of 17c) Which of the following correspond to functions fun1, fun2, fun3, and fun4?push %ebpmov %esp,%ebpmov 0x8(%ebp),%eaxmovswl 0x4(%eax),%eaxpop %ebpretANSWER: ________push %ebpmov %esp,%ebpmov 0x8(%ebp),%eaxmov 0x8(%eax),%eaxmovswl 0x4(%eax),%eaxpop %ebpretANSWER: ________push %ebpmov %esp,%ebpmov 0x8(%ebp),%eaxmov 0x20(%eax),%eaxpop %ebpretANSWER: ________push %ebpmov %esp,%ebpmov 0x8(%ebp),%eaxadd $0x20,%eaxpop %ebpretANSWER: ________Page 5 of 17d) Assume a variable is declared as struct s2 myS2; and the storage for this variable begins at ad-dress 0xbfbdc300.(gdb) x/20w &myS20xbfbdc300: 0x000000d5 0x0000000f 0xbfbdc338 0x000000000xbfbdc310: 0x000000ff 0x0000012c 0x01020501 0xb7f0a6030xbfbdc320: 0x0000000c 0x080496a0 0xbfbdc338 0x0804828d0xbfbdc330: 0xb7ed9fd5 0xb7fc1ff4 0x000000f3 0x080400120xbfbdc340: 0xb7eda0b9 0xb7fc1ff4 0xbfbdc3a8 0xb7ec6dceFill in all the blanks below.HINTS: Label the fields. Not all 20 words are used. Remember endianness!What would be returned by:fun1(&myS2) = 0x___________fun2(&myS2) = 0x___________fun3(&myS2) = 0x___________fun4(&myS2) = 0x___________What is the value of:myS2.b->y = 0x___________myS2.a.y = 0x___________myS2.z = 0x___________myS2.e[1] = 0x___________Page 6 of 17Problem 3. (13 points):This problem concerns assembly code generated by GCC for a function containing a switch statement onan x86-64 machine.Below is the entire assembly dump of the function selector, whose C skeleton is given subsequently.0000000000400470 <selector>:400470: 8d 46 01 lea 0x1(%rsi),%eax400473: 83 f8 06 cmp $0x6,%eax400476: 77 1a ja 400492 <selector+0x22>400478: 89 c0 mov %eax,%eax40047a: ff 24 c5 a0 05 40 00 jmpq*0x4005a0(,%rax,8)400481: 48 83 c7 04 add $0x4,%rdi400485: eb 0e jmp 400495 <selector+0x25>400487: 8b 37 mov (%rdi),%esi400489: eb 0a jmp 400495 <selector+0x25>40048b: d1 fe sar %esi40048d: 83 c6 05 add $0x5,%esi400490: eb 03 jmp 400495 <selector+0x25>400492: 8d 34 f6 lea (%rsi,%rsi,8),%esi400495: 48 63 c6 movslq %esi,%rax400498: 8b 04 87 mov (%rdi,%rax,4),%eax40049b: c3 retqThe code at line 40047a uses an indirect jump to index into a jump table:40047a: ff 24 c5 a0 05 40 00 jmpq*0x4005a0(,%rax,8)In GDB, we examine the memory dump at address 0x4005a0 which produces the following output:(gdb) x /8g 0x4005a00x4005a0: 0x0000000000400487 0x00000000004004810x4005b0: 0x0000000000400492 0x000000000040048d0x4005c0: 0x000000000040048b 0x00000000004004920x4005d0: 0x0000000000400481 0x0000002c3b031b01Page 7 of 17Fill in the blank portions of C code below to reproduce the function corresponding to this object code.int selector (int*x, int y) {switch (y) {case ____:case ____:____________;break;case ____:y = ________;break;case ____:y = ________;case ____:y = ________;break;default:y = ________;}return ________;}Page 8 of 17Problem 4. (13 points):The function below is hand-written assembly code for a sorting algorithm. Fill in the blanks on the nextpage by converting this assembly to C code..globl mystery_sort # exports the symbol so other .c files# can call the functionmystery_sort:dec %rsixor %rdx, %rdxinc %rdxjmp loop1_checkloop1:xor %rdx, %rdxmov %rsi, %rcxjmp loop2_checkloop2:dec %rcxmov 8(%rdi, %rcx, 8), %r8mov (%rdi, %rcx, 8), %r9cmp %r8, %r9jle loop2_checkmov %r8, (%rdi, %rcx, 8)mov %r9, 8(%rdi, %rcx, 8)inc %rdxloop2_check:test %rcx, %rcxjnz loop2loop1_check:test %rdx, %rdxjnz loop1retPage 9 of 17void mystery_sort (long*array, long len){long a, b, tmp;do{a = _____;for (b = _____; b > _____; b--){if (array[_____] > array{_____]){tmp = array[_____];array[_____] = array[_____];array[_____] = tmp;a++;}}} while (a > _____);}Page 10 of 17Problem 5. (22 points):Circle the correct answer.1. What register is the return value from a function stored in? (Assume 32 bit return value)(a) eip(b) ebp(c) eax(d) esp2. The pushl instruction does what to the stack pointer?(a) decrements the stack pointer by 4 bytes(b) decrements the stack pointer by 1 byte(c) increments the stack pointer by 4 bytes(d) increments the stack pointer by 1 byte3. What does the test instruction do before setting condition flags?(a) bitwise and(b) subtraction(c) bitwise xor(d) bitwise bang4. On the x8664 fish machines, what is the size of an int?(a) 1 byte(b) 32 bytes(c) 4 bytes(d) 8 bytes5. Which of the following represents the order of the registers that store the first four arguments to afunction in x8664?(a) rdi, rsi, rcx, rdx(b) rax, rbx, rsi, rdi(c) rsi, rdi, rdx, rbx(d) rdi, rsi, rdx, rcxPage 11 of 176. The ˜ operator performs what operation on a value?(a) bitwise complement(b) logical complement(c) reverses the order of


View Full Document

CMU CS 15213 - Exam

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

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