没有合适的资源?快使用搜索试试~ 我知道了~
深入理解计算机系统(英文版答案)
需积分: 50 4 下载量 51 浏览量
2011-11-21
20:24:44
上传
评论
收藏 326KB PDF 举报
温馨提示
书中主要介绍了要介绍了计算机系统的基本概念,包括最底层的内存中的数据表示、流水线指令的构成、虚拟存储器、编译系统、动态加载库,以及用户应用等.这是课后答案。
资源推荐
资源详情
资源评论
Computer Systems: A Programmer’s Perspective
Instructor’s Solution Manual
1
Randal E. Bryant
David R. O’Hallaron
December 4, 2003
1
Copyright
c
2003, R. E. Bryant, D. R. O’Hallaron. All rights reserved.
2
Chapter 1
Solutions to Homework Problems
The text uses two different kinds of exercises:
Practice Problems. These are problems that are incorporated directly into the text, with explanatory
solutions at the end of each chapter. Our intention is that students will work on these problems as they
read the book. Each one highlights some particular concept.
Homework Problems. These are found at the end of each chapter. They vary in complexity from
simple drills to multi-week labs and are designed for instructors to give as assignments or to use as
recitation examples.
This document gives the solutions to the homework problems.
1.1 Chapter 1: A Tour of Computer Systems
1.2 Chapter 2: Representing and Manipulating Information
Problem 2.40 Solution:
This exercise should be a straightforward variation on the existing code.
code/data/show-ans.c
1 void show_short(short int x)
2 {
3 show_bytes((byte_pointer) &x, sizeof(short int));
4 }
5
6 void show_long(long int x)
7 {
8 show_bytes((byte_pointer) &x, sizeof(long));
9 }
1
2
CHAPTER 1. SOLUTIONS TO HOMEWORK PROBLEMS
10
11 void show_double(double x)
12 {
13 show_bytes((byte_pointer) &x, sizeof(double));
14 }
code/data/show-ans.c
Problem 2.41 Solution:
There are many ways to solve this problem. The basic idea is to create some multibyte datum with different
values 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 an
int. This byte will equal 0 on a big-endian machine and 1 on a little-endian machine.
code/data/show-ans.c
1 int is_little_endian(void)
2 {
3 /* MSB = 0, LSB = 1 */
4 int x = 1;
5
6 /* Return MSB when big-endian, LSB when little-endian */
7 return (int) (* (char *) &x);
8 }
code/data/show-ans.c
Problem 2.42 Solution:
This is a simple exercise in masking and bit manipulation. It is important to mention that ˜0xFF is a way
to 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 think
of it as logical negation. More generally, it detects whether there is any nonzero bit in a word.
A. !!x
B. !!˜x
C. !!(x & 0xFF)
D. !!(˜x & 0xFF)
Problem 2.44 Solution:
1.2. CHAPTER 2: REPRESENTING AND MANIPULATING INFORMATION
3
There are many solutions to this problem, but it is a little bit tricky to write one that works for any word
size. Here is our solution:
code/data/shift-ans.c
1 int int_shifts_are_arithmetic()
2 {
3 int x = ˜0; /* All 1’s */
4
5 return (x >> 1) == x;
6 }
code/data/shift-ans.c
The above code peforms a right shift of a word in which all bits are set to 1. If the shift is arithmetic, the
resulting word will still have all bits set to 1.
Problem 2.45 Solution:
This problem illustrates some of the challenges of writing portable code. The fact that 1<<32 yields 0 on
some 32-bit machines and 1 on others is common source of bugs.
A. The C standard does not define the effect of a shift by 32 of a 32-bit datum. On the SPARC (and
many other machines), the expression x << k shifts by
, i.e., it ignores all but the least
significant 5 bits of the shift amount. Thus, the expression 1 << 32 yields 1.
B. Compute beyond_msb as 2 << 31.
C. We cannot shift by more than 15 bits at a time, but we can compose multiple shifts to get the
desired effect. Thus, we can compute set_msb as 2 << 15 << 15, and beyond_msb as
set_msb << 1.
Problem 2.46 Solution:
This problem highlights the difference between zero extension and sign extension. It also provides an excuse
to show an interesting trick that compilers often use to use shifting to perform masking and sign extension.
A. The function does not perform any sign extension. For example, if we attempt to extract byte 0 from
word 0xFF, we will get 255, rather than
.
B. The following code uses a well-known trick for using shifts to isolate a particular range of bits and to
perform sign extension at the same time. First, we perform a left shift so that the most significant bit
of the desired byte is at bit position 31. Then we right shift by 24, moving the byte into the proper
position and peforming sign extension at the same time.
code/data/xbyte.c
1 int xbyte(packed_t word, int bytenum)
2 {
剩余88页未读,继续阅读
资源评论
Golang技术栈
- 粉丝: 5
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- MATLAB运动汽车測試視頻素材
- 中国95后年轻人视频消费机密报告.pdf
- 中国Android手机用户隐私安全认知调查报告.pdf
- 中国Android手机预装产业及用户使用情况研究报告.pdf
- 微电网二次控制,下垂控制,具有通信延迟的微电网分布式事件触发二次控制,实现了二次控制,效果好,有相关参考文献
- 中国互联网影视产业报告.pdf
- 中国消费者趋势2016.pdf
- matlab平台的 BP的水果识别.zip
- 中国专车市场分析报告.pdf
- 中秋&十一出行预测&交通指南.pdf
- 转型中的中国科研.pdf
- matlab平台的 BP神经网络的火焰识别.zip
- 澳大利亚5区14机59节点模型,可研究调压,调频,无功补偿,新能源并网等暂态
- 源荷不确定性 考虑源荷随机特征的热电联供微网优化matlab 复现王锐的《含可再生能源的热电联供型微网经济运行优化》 由风电机组、光伏电池、燃料电池、余热锅炉、燃气锅炉、蓄电池以及热电负荷构成的热电联
- python-3.13.1-amd64
- matlab平台的 GUI的水果识别.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功