DOC PREVIEW
Berkeley COMPSCI 61C - Final Exam Answers

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

Save
View full document
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
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
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
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
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
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:

M1a. Remember that overflow is defined as the result of the operation making nosense, which in 2's complement representation is equivalent to themathematical result not fitting in the format. – if any of the operands is zero, there is no overflow– if one of the operands is positive, and the other is negative, there can be nooverflow– if the two operands have the same sign, we have the following cases: 10 (-2) + 10 (-2) = 00 (0 != -4) 1 case11 (-1) + 10 (-2) = 01 (1 != -3) 1 case10 (-2) + 11 (-1) = 01 (1 != -3) 1 case01 (1) + 01 (1) = 10 (-2 != 2) 1 caseSo there are 4 cases from the total 16.M1b. The easiest solution is to represent all possible values. An 8-bit exponent covers [0–255], which with 127 bias means [-127–128]. Nibble for a float. SEEM. Exponent bias = 1, thus 00,01,10,11 = 0,1,2,3 -1,0,1,2Exponen t Sign i f i c a n d Obje c t0 0 00 nonze ro Denorm 1-254 any t h i n g +/- f l. pt. #255 0 +/- ∞255 nonze ro NaN 1 00 0 | - 01 00 1 | denorm: 0.1 x 20 = 0.1 = 1/21 01 0 | - 1.0 x 20 = -11 01 1 | - 1.1 x 20 = -1.51 10 0 | - 1.0 x 21 = 10 = -21 10 1 | - 1.1 x 21 = 10 = -31 11 0 | reserved for –∞1 11 1 | reserved for NaN…similarly for positive numbersAns: MostNeg= [ -3 = 0b1101 = 0xD], SmallestPos = [1/2 = 0b0001 =0x1]NextSmallestPos = [1=0b0010=0x2]M2a.Static = 0 (no globals)Stack = 4 (1 pointer)Heap = 48 (2 * [8 (2 ints) + 4 (4 chars) + 8 (2 ptrs) + 4 (1 ptr)]) = 2*24 = 48M2b.Advan t a g e: Save s a mal l o c ca l l (cou l d ta k e a lo n gt i me to sea r c h f r e e l i s t ) Ale x: l e s s i n t e r n a lf r a gmen t a t i o n (?), f r e e i n g on l y req u i r e s one ca l l(les s prog r amme r e f f o r t )Disadvan t a g e : Migh t no t succ e e d wher e the o t h e rwou l d have (i f memory f r a gmen t e d no t one la r g e chunkbu t two sma l l e r chunk s), we have to wa i t un t i l bo t hare unuse d be f o r e we can f r e e!M2c.T F We d i s c u s s e d 3 schemes: K&R, s l a b al l o c a t o r ,and th e buddy sys t em . I t’ s poss i b l e to wr i t ecode to make any of the s e the bes t and any ofthe s e the wor s t pe r f o r m e r (i.e., one wi l lneve r a lwa y s dom i na t e ano t h e r, pe r f o r m a n c e -wis e).One of the t r u i s m s abou t the s e schemes i s tha t t h e r ei s no s i n g l e bes t one.T F Mark and sweep ga r b a g e co l l e c t i o n does no twor k f o r c i r c u l a r da t a s t r u c t u r e s .Tha t’ s re f e r e n c e coun t i n g to whi c h you’ r e re f e r r i n g ,my f r i e n d.T F I f you wro t e code th a t had no ca l l s to freeand we on l y gar b a g e co l l e c t when we have to,re f e r e n c e coun t i n g wi l l st a r t co l l e c t i n gbe f o r e cop y i n g .Copy i n g wou l d s t a r t co l l e c t i n g be f o r e RC, becaus e i tHAS to GC when the memory i s ha l f - fu l l (RC canwa i t un t i l i t ’ s v i r t u a l l y a l l fu l l ) .M3. (a): NO. Po i n t e r t y p e s (to f l o a t and to po i n t e r tod l i s t ) have the same s i z e. Once th i s has been sa i d, t h eau t h o r of l i n e (a) shou l d be t u r n e d i n t o sha r k ba i t. (b): NO. Po i n t e r ar i t h m e t i c i s f i n e. (c): CT. “p[i][ j].nex t ” req u i r e s a “s t r u c t d l i s t *”ass i g nmen t. p[i][ j] i s a “s t r u c t d l i s t ” , so th e r i g h tpas t shou l d be pr e c e d e d by an amper s a n d. Rig h t: p[i][ j].nex t = &(p[i][ j+1]);(d): RT, th e la s t i t e r a t i o n i s ou t of bound. Note th a tth i s er r o r occu r s on l y when the ou t- of- bound memoryi s pro t e c t e d . Othe rw i s e , we are ju s t ove rw r i t i n gano t h e r pos i t i o n of memor y. I f we are un l u c k y , tha t“ano t h e r pos i t i o n o f memor y” wi l l co r r e s p o n d to theheap meta d a t a, and we wi l l rea l i z e th i s on l y whent r y i n g to …


View Full Document

Berkeley COMPSCI 61C - Final Exam Answers

Documents in this Course
SIMD II

SIMD II

8 pages

Midterm

Midterm

7 pages

Lecture 7

Lecture 7

31 pages

Caches

Caches

7 pages

Lecture 9

Lecture 9

24 pages

Lecture 1

Lecture 1

28 pages

Lecture 2

Lecture 2

25 pages

VM II

VM II

4 pages

Midterm

Midterm

10 pages

Load more
Download Final Exam Answers
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 Final Exam Answers 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 Final Exam Answers 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?