DOC PREVIEW
UCLA COMSCI 33 - CS33-midterm-2013_Soln_All

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:

UntitledUNIVERSITY 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: ___________ Total: ________________  `` BERKELEY • DAVIS •IRVINE • LOS ANGELES • RIVERSIDE •SAN DIEGO • SAN FRANCISCO SANTA BARBARA • SANTA CRUZ SOLUTIONS867530911. C If You Can Solve This (28 points): The following problem assumes the following declarations:int x = rand();int y = rand();int z = rand();float f= foo(); // f is not NaNunsigned ux = (unsigned) x;unsigned uy = (unsigned) y;For the following C expressions, circle either Y or N (but not both).Always True? a. ((float) x + f) - f == (float) x Y N b. (ux*uy) == (x*y) Y N c. ((x&8) | y) == y)  (x<<28)>0 Y N d. (x^y)^x + z == y+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? Let x=1 and f=1e20, rounding will cause the lhs to evaluate to zero.Mixed integers will be implicitly casted to unsignedProperty of xor, an example is in the inplace swap function from lecture and textLet x =0xFFFFFFFF and y = 0x822. This Problem Bytes (21 points): Consider the following 8 bits:10111100 We will interpret these bits in three different ways (assume the above is in big endian form): a. An 8-bit unsigned integerb. An 8-bit two’s complement integerc. The 8-bit floating point format we covered in class27+06+25+24+23+22+01+00=128+32+16+8+4=188-27+06+25+24+23+22+01+00=-128+32+16+8+4=-681 0111 100 (-1)sMx2E, M =1.f, E=e-biass e f bias=7 M=1.100=20+(1/21)=1.5 E=0111-7=0 10111100 = -1.5x20=-3/222. This Problem Bytes (21 points): Consider the following 8 bits:10101100 We will interpret these bits in three different ways (assume the above is in big endian form): a. An 8-bit unsigned integerb. An 8-bit two’s complement integerc. The 8-bit floating point format we covered in class27+06+25+04+23+22+01+00=128+32+8+4=172-27+06+25+04+23+22+01+00=-128+32+8+4=-841 0101 100 s e f (-1)sMx2E, M =1.f, E=e-bias bias=7M=1.100=20+(1/21)=1.5 E=0101-7=-210101100 = -1.5x2-2=-3/822. This Problem Bytes (21 points): Consider the following 8 bits:10011100 We will interpret these bits in three different ways (assume the above is in big endian form): a. An 8-bit unsigned integerb. An 8-bit two’s complement integerc. The 8-bit floating point format we covered in class27+06+05+24+23+22+01+00=128+16+8+4=156-27+06+05+24+23+22+01+00=-128+16+8+4=-1001 0011 100 s e f (-1)sMx2E, M =1.f, E=e-bias bias=7M=1.100=20+(1/21)=1.5 E=0011-7=-410011100 = -1.5x2-4=-3/3222. This Problem Bytes (21 points): Consider the following 8 bits:10110100 We will interpret these bits in three different ways (assume the above is in big endian form): a. An 8-bit unsigned integerb. An 8-bit two’s complement integerc. The 8-bit floating point format we covered in class27+06+25+24+03+22+01+00=128+32+16+4=180-27+06+25+24+03+22+01+00=-128+32+16+4=-761 0110 100 s e f (-1)sMx2E, M =1.f, E=e-bias bias=7M=1.100=20+(1/21)=1.5 E=0110-7=-1 10110100 = -1.5x2-1=-3/433. And This One is a Pain in My Big Endian (51 points): Here’s your chance to show your bomb labskills. Below we show the disassembled function func0() – compiled on an ia32 machine. The functionreads one integer, using scanf(). Your job is to provide the input to scanf() that will result in thisfunction returning the value 42, 23, 0, 83.To help you with this task – we provide part of the C code for the function below:int func0 (int j, int k) { int a; int i; a=0; // a will be modified by the switch statement scanf("%d", &i); // THE INPUT YOU ARE FIGURING OUT switch(i){ … } return a; } where the …’s above represent missing code you need to figure out. In addition to the input that would result in this function returning a 42, 23, 0, 83, please fill in the blanks we have on the answer key with the requested intermediate values that would help you answer this question. The next two pages contain everything you need for this problem.4Here’s the function from objdump: 08048470 <func0>: 8048470: 55 push %ebp 8048471: 89 e5 mov %esp,%ebp 8048473: 83 ec 28 sub $0x28,%esp 8048476: 8d 45 f4 lea -0xc(%ebp),%eax 8048479: 89 5d f8 mov %ebx,-0x8(%ebp) 804847c: 8b 5d 08 mov 0x8(%ebp),%ebx 804847f: 89 75 fc mov %esi,-0x4(%ebp) 8048482:8b 75 0c mov 0xc(%ebp),%esi 8048485: 89 44 24 04 mov %eax,0x4(%esp) 8048489: c7 04 24 64 86 04 08 movl $0x8048664,(%esp) 8048490: e8 07 ff ff ff call 804839c <__isoc99_scanf@plt> 8048495: 83 7d f4 07 cmpl $0x7,-0xc(%ebp) 8048499: 76 15 jbe 80484b0 <func0+0x40> 804849b: 89 d8 mov %ebx,%eax 804849d: 89 f1 mov %esi,%ecx 804849f: 8b 5d f8 mov -0x8(%ebp),%ebx 80484a2: 8b 75 fc mov -0x4(%ebp),%esi 80484a5: d3 e0 shl %cl,%eax 80484a7: 89 ec mov %ebp,%esp 80484a9: 5d pop %ebp 80484aa: c3 ret 80484ab: 90 nop 80484ac: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 80484b0: 8b 45 f4 mov -0xc(%ebp),%eax 80484b3: ff 24 85 74 86 04 08 jmp *0x8048674(,%eax,4) 80484ba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 80484c0: 89 f0 mov %esi,%eax 80484c2: 8b 75 fc mov -0x4(%ebp),%esi 80484c5: 21 d8 and %ebx,%eax 80484c7: 8b 5d f8 mov -0x8(%ebp),%ebx 80484ca: 89 ec mov %ebp,%esp 80484cc: 5d pop %ebp 80484cd: c3 ret 80484ce: 66 90 xchg %ax,%ax 80484d0: 8d 04 1e lea (%esi,%ebx,1),%eax 80484d3: 8b 5d f8 mov -0x8(%ebp),%ebx 80484d6: 8b 75 fc mov -0x4(%ebp),%esi 80484d9: 89 ec mov %ebp,%esp 80484db: 5d pop %ebp 80484dc: c3 ret 80484dd: 8d 76 00 lea 0x0(%esi),%esi 80484e0: 89 d8 mov %ebx,%eax 80484e2: 8b 5d f8 mov -0x8(%ebp),%ebx 80484e5: 29 f0 sub %esi,%eax 80484e7: 8b 75 fc mov


View Full Document

UCLA COMSCI 33 - CS33-midterm-2013_Soln_All

Download CS33-midterm-2013_Soln_All
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-2013_Soln_All 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-2013_Soln_All 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?