深入了解计算机系统作业答案,深入理解计算机系统习题答案.pdf

a7f4a3f590493a1e451dd952a488fd7c.gif 深入理解计算机系统习题答案.pdf

(89页)

ac1f0c7f89c7a4c8682dabe8b0779eb9.png

本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!

11.90 积分

Computer Systems: A Programmer's PerspectiveInstructor's Solution Manual 1Randal E. BryantDavid R. O'HallaronDecember 4, 20031Copyright c 2003, R. E. Bryant, D. R. O'Hallaron. All rights reserved.2Chapter 1Solutions to Homework ProblemsThe text uses two different kinds of exercises:  Practice Problems. These are problems that are incorporated directly into the text, with explanatorysolutions at the end of each chapter. Our intention is that students will work on these problems as theyread the book. Each one highlights some particular concept.  Homework Problems. These are found at the end of each chapter. They vary in complexity fromsimple drills to multi-week labs and are designed for instructors to give as assignments or to use asrecitation examples.This document gives the solutions to the homework problems.1.1 Chapter 1: A Tour of Computer Systems1.2 Chapter 2: Representing and Manipulating InformationProblem 2.40 Solution:This exercise should be a straightforward variation on the existing code.code/data/show-ans.c1 void show_short(short int x)2 {3 show_bytes((byte_pointer) &x, sizeof(short int));4 }56 void show_long(long int x)7 {8 show_bytes((byte_pointer) &x, sizeof(long));9 }12 CHAPTER 1. SOLUTIONS TO HOMEWORK PROBLEMS1011 void show_double(double x)12 {13 show_bytes((byte_pointer) &x, sizeof(double));14 }code/data/show-ans.cProblem 2.41 Solution:There are many ways to solve this problem. The basic idea is to create some multibyte datum with differentvalues for the most and least-significant bytes. We then read byte 0 and determine which byte it is.In the following solution is to create an int with value 1. We then access its first byte and convert it to anint. This byte will equal 0 on a big-endian machine and 1 on a little-endian machine.code/data/show-ans.c1 int is_little_endian(void)2 {3 /* MSB = 0, LSB = 1 */4 int x = 1;56 /* Return MSB when big-endian, LSB when little-endian */7 return (int) (* (char *) &x);8 }code/data/show-ans.cProblem 2.42 Solution:This is a simple exercise in masking and bit manipulation. It is important to mention that ˜0xFF is a wayto generate a mask that selects all but the least significant byte that works for any word size.(x & 0xFF) | (y & ˜0xFF)Problem 2.43 Solution:These exercises require thinking about the logical operation ! in a nontraditional way. Normally we thinkof it as logical negation. More generally, it detects whether there is any nonzero bit in a word.A. !!xB. !!˜xC. !!(x & 0xFF)D. !!(˜x & 0xFF)Problem 2.44 Solution:1.2. CHAPTER 2: REPRESENTING AND MANIPULATING INFORMATION 3There are many solutions to this problem, but it is a little bit tricky to write one that works for any wordsize. Here is our solution:code/data/shift-ans.c1 int int_shifts_are_arithmetic()2 {3 int x = ˜0; /* All 1’s */45 return (x >> 1) == x;6 }code/data/shift-ans.cThe above code p。省略部分。ntations, their precision, and theirranges.A. The number will have §¨, ¨0£© , 0)© , and . The exponent bitswill be ¨¨ and the fraction bits will be ¨¨.B. The largest odd integer that can be represented exactly will have a binary representation consistingof # 1s. It will have § , ¨ © ¨¨0¨¨', © ¨¨0¨', anda value ¨ () . The bit representation of the exponent will be the binary representation of#¨£'*) . The bit representation of the fraction will be © ¨¨ © .C. The reciprocal of the smallest positive normalized value will have value ¨0'0. It will have§¨£'*)¨, ¨ , and . The bit representation of the exponent will be © ¨¨. The bitrepresentation of the fraction will be ¨¨.Problem 2.58 Solution:8 CHAPTER 1. SOLUTIONS TO HOMEWORK PROBLEMSThis exercise is of practical value, since Intel-compatible processors perform all of their arithmetic in ex-tended precision. It is interesting to see how adding a few more bits to the exponent greatly increases therange of values that can be represented.Description Extended precisionValue DecimalSmallest denorm. ¨'¥£¨'*)¥£¡ 0§3'©¡£)Smallest norm. ¨'*)¥£¡ 0§§'©¡£0Largest norm. ©¨£¢¨)¥£¡ §£¡©¡£0Problem 2.59 Solution:We have found that working through floating point representations for small word sizes is very instructive.Problems such as this one help make the description of IEEE floating point more concrete.Description Hex ¨§8000 ¨Smallest value ¤3F01 0£ 0£¥0£ 0£¥256 4700 ¦ —Largest denormalized 00FF 0££0£¥¨¨¨' ¦¥¨§FF00 — — —Number with hex representation 3AA0 —)£ )£0£¥Problem 2.60 Solution:This problem requires students to think of the relationship between int, float, and double.A. (double)(float) x == dx. No. Try x =  ¢¡© £0 . Note that it is true with Linux/GCC, sinceit uses a extended precision representation for both double and float.B. dx + dy == (double) (y+x). No. Let x = y =  ¢¡¢££0 .C. dx + dy + dz == dz + dy + dx. Yes. Since each value ranges between  ¢¡¢££0 and  ¢¡© £0 ,their sum can be represented exactly.D. dx * dy * dz == dz * dy * dx. No. Let dx =  ¢¡© £0 , dy=  ¢¡© £0 , dz =  ¢¡© £0¨. (Not detected with Linux/gcc)E. dx / dx == dy / dy. No. Let x = 0, y = 1.Problem 2.61 Solution:This problem helps students understand the relation between the different categories of numbers. Gettingall of the cutoff thresholds correct is fairly tricky. Our solution file contains testing code.code/data/fpwr2-ans.c 关 键 词: 习题 理解 深入 系统 答案 计算机

4d91c43bfc72ca913299809b07b4968f.gif  天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值