DOC PREVIEW
UCLA COMSCI 33 - CS33-midterm-2012-a

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 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 10 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 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

UNIVERSITY OF CALIFORNIA, LOS ANGELES UCLA CS 33 Midterm All answers must be written on the answer sheet (last page of the exam). All work should be written directly on the exam, use the backs of pages if needed. This is an open book, open notes quiz – but you cannot share books or notes. An ASCII table is on the second to last page if you need it. I will follow the guidelines of the university in reporting academic misconduct – please do not cheat. NAME: ________________________________________________________________ ID: ____________________________________________________________________ Problem 1: ___________ Problem 2: ___________ Problem 3: ___________ Problem 4: ___________ Problem 5: ___________ Total: ________________  `` BERKELEY • DAVIS • IRVINE • LOS ANGELES • RIVERSIDE • SAN DIEGO • SAN FRANCISCO SANTA BARBARA • SANTA CRUZ11. C If You Can Solve This (12 points): The following problem assumes the following declarations: int x = rand(); int y = rand(); int z = rand(); float f= foo(); // f is not NaN unsigned ux = (unsigned) x; unsigned uy = (unsigned) y; For the following C expressions, circle either Y or N (but not both). Always True? a. (0+f)-f == 0 Y N b. (ux-uy) == (x-y) Y N c. ((((x<<1)^x)-x)>>1) == x ⇒⇒⇒⇒ !((x&12) == 12) Y N d. (x^y)^z == y ⇒⇒⇒⇒ x==z Y N Note that “⇒⇒⇒⇒” represents an implication. A ⇒⇒⇒⇒ B means that you assume A is true, and your answer should indicate whether B should be implied by A – i.e. given that A is true, is B always true? 2. What Size Is It? (4 points): Consider the following structure definition: struct product { unsigned short ID; union NameOrSerial { char name[8]; unsigned int serial; } label; } my_data[100]; How many bytes would my_data consume in memory on an x86-64 Linux machine?23. Four Perspectives on a Bit Vector (9 points): Consider the following 8 bits: 10101011 We will interpret these bits in three different ways (assume the above is in big endian form): a. An 8-bit unsigned integer b. An 8-bit two’s complement integer c. The 8-bit floating point format we covered in class34. This Problem is a Pain in My Big Endian (35 points): Consider the following structure declaration: struct my_struct{ int val; char a; char b; short small_num; char * label; struct my_struct * left_child; struct my_struct * right_child; }; We compile code using this struct on a 32-bit little endian machine, and insert a number of nodes into the structure. The following gdb interaction provides enough details to reverse engineer a tree built from these structs. (gdb) print the_top $3 = (struct my_struct *) 0x100130 (gdb) x/96x 0x100130 0x100130: 0x0000000a 0x00d91107 0x00001f8e 0x001001f0 0x100140: 0x00100210 0x00000000 0x00000000 0x00000000 0x100150: 0x00000005 0x00c8020a 0x00001f71 0x00100190 0x100160: 0x00100170 0x00000000 0x00000000 0x00000000 0x100170: 0x00000012 0x00431e18 0x00001f76 0x001001b0 0x100180: 0x00000000 0x00000000 0x00000000 0x00000000 0x100190: 0x00000003 0x0055180d 0x00001f7a 0x00000000 0x1001a0: 0x00000000 0x00000000 0x00000000 0x00000000 0x1001b0: 0x0000000d 0x00b3020c 0x00001f80 0x001001d0 0x1001c0: 0x00000000 0x00000000 0x00000000 0x00000000 0x1001d0: 0x00000008 0x00111707 0x00001f87 0x00000000 0x1001e0: 0x00000000 0x00000000 0x00000000 0x00000000 0x1001f0: 0x00000005 0x002f1418 0x00001f95 0x00100230 0x100200: 0x00100250 0x00000000 0x00000000 0x00000000 0x100210: 0x0000000f 0x00050d11 0x00001f9a 0x00100270 0x100220: 0x00100290 0x00000000 0x00000000 0x00000000 0x100230: 0x00000003 0x006b1518 0x00001f9f 0x00000000 0x100240: 0x00000000 0x00000000 0x00000000 0x00000000 0x100250: 0x00000008 0x00070816 0x00001fa5 0x00000000 0x100260: 0x00000000 0x00000000 0x00000000 0x00000000 0x100270: 0x0000000d 0x00481219 0x00001fab 0x00000000 0x100280: 0x00000000 0x00000000 0x00000000 0x00000000 0x100290: 0x00000012 0x00410213 0x00001fb1 0x00000000 0x1002a0: 0x00000000 0x00000000 0x00000000 0x00000000 (continued on next page)4(gdb) x/32x 0x00001f60 0x1f60: 0x00000000 0x00201868 0x1425ff00 0x90000020 0x1f70: 0x756c6200 0x65720065 0x72670064 0x006e6565 0x1f80: 0x6c6c6579 0x7000776f 0x6c707275 0x726f0065 0x1f90: 0x65676e61 0x756c7000 0x6570006d 0x6d007261 0x1fa0: 0x6e6f6c65 0x72656200 0x67007972 0x65706172 0x1fb0: 0x70706100 0x0100656c 0x1c000000 0x00000000 0x1fc0: 0x1c000000 0x00000000 0x1c000000 0x02000000 0x1fd0: 0x90000000 0x3400000b 0x34000000 0x31000000 Using this information, find the struct in the tree where val is equal to 13, and report the corresponding label (i.e. the actual string). Also, please fill in the blanks we have on the answer key with the requested intermediate values that would help you answer this question. Hint – don’t forget that gdb reverses byte ordering within each 4-byte chunk. So in the following dump: (gdb) x/4x 0x00111110 0x111110: 0x33221100 0x77665544 0xBBAA9988 0xFFEEDDCC This prints out 16 bytes of memory starting at address 0x111110. In this example, the 16 bytes of memory starting at 0x111110 would contain, in order from lowest address (0x111110) to highest address (0x11111F): 00112233445566778899AABBCCDDEEFF So address 0x111110 contains the byte 0x00, address 0x111111 contains the byte 0x11, address 0x111112 contains the byte 0x22, and so on. So in terms of just the least significant hex place of the address, gdb is actually printing out addresses in the following order: 3 2 1 0 7 6 5 4 B A 9 8 F E D C This is useful when reading words, but can be confusing for other values.55. Revenge of the Bomb Lab (40 points): Here’s your chance to show your bomb lab skills. Below we show the disassembled function dud1() – compiled on an x86-64 machine. The function does not take any parameters – but does read some number of integers, one at a time, using scanf (this is the callq instruction below). Your job is to provide the input that will result in this function returning the value 1 (i.e. 0x1 will be in %rax). To help you with this task – we provide part of the C code for the function below (note that MAX_FIRST and SIZE are macros that would be replaced with constants at compile


View Full Document

UCLA COMSCI 33 - CS33-midterm-2012-a

Download CS33-midterm-2012-a
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 CS33-midterm-2012-a 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 CS33-midterm-2012-a 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?