深入理解计算机系统第二版家庭作业答案
深入理解计算机系统习题答案
1
2
10 11 12 13 14
CHAPTER 1. SOLUTIONS TO HOMEWORK PROBLEMS
void show_double(double x) { show_bytes((byte_pointer) &x, sizeof(double)); } code/data/show-ans.c
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.
Problem 2.40 Solution: This exercise should be a straightforward variation on the existing code.
code/data/show-ans.c
1 2 3 4 5 6 7 8 9
void show_short(short int x) { show_bytes((byte_pointer) &x, sizeof(short int)); } void show_long(long int x) { show_bytes((byte_pointer) &x, sizeof(long)); }
code/data/show-ans.c
1 2 3 4 5 6 7 8
int is_little_endian(void) { /* MSB = 0, LSB = 1 */ int x = 1; /* Return MSB when big-endian, LSB when little-endian */ return (int) (* (char *) &x); } code/data/show-ans.c
计算机操作系统第二版答案
习题一1.什么是操作系统?它的主要功能是什么?答:操作系统是用来管理计算机系统的软、硬件资源,合理地组织计算机的工作流程,以方便用户使用的程序集合;其主要功能有进程管理、存储器管理、设备管理和文件管理功能。
2.什么是多道程序设计技术?多道程序设计技术的主要特点是什么?答:多道程序设计技术是把多个程序同时放入内存,使它们共享系统中的资源;特点:(1)多道,即计算机内存中同时存放多道相互独立的程序;(2)宏观上并行,是指同时进入系统的多道程序都处于运行过程中;(3)微观上串行,是指在单处理机环境下,内存中的多道程序轮流占有CPU,交替执行。
3.批处理系统是怎样的一种操作系统?它的特点是什么?答:批处理操作系统是一种基本的操作系统类型。
在该系统中,用户的作业(包括程序、数据及程序的处理步骤)被成批的输入到计算机中,然后在操作系统的控制下,用户的作业自动地执行;特点是:资源利用率高、系统吞吐量大、平均周转时间长、无交互能力。
4.什么是分时系统?什么是实时系统?试从交互性、及时性、独立性、多路性和可靠性几个方面比较分时系统和实时系统。
答:分时系统:一个计算机和许多终端设备连接,每个用户可以通过终端向计算机发出指令,请求完成某项工作,在这样的系统中,用户感觉不到其他用户的存在,好像独占计算机一样。
实时系统:对外部输入的信息,实时系统能够在规定的时间内处理完毕并作出反应。
比较:(1)交互性:实时系统具有交互性,但人与系统的交互,仅限于访问系统中某些特定的专用服务程序。
它不像分时系统那样向终端用户提供数据处理、资源共享等服务。
实时系统的交互性要求系统具有连续人机对话的能力,也就是说,在交互的过程中要对用户得输入有一定的记忆和进一步的推断的能力。
(2)及时性:实时系统对及时性的要求与分时系统类似,都以人们能够接受的等待时间来确定。
而及时系统则对及时性要求更高。
(3)独立性:实时系统与分时系统一样具有独立性。
每个终端用户提出请求时,是彼此独立的工作、互不干扰。
深入理解计算机系统(第二版) 家庭作业答案
int int_shifts_are_arithmetic(){int x = -1;return (x>>1) == -1;}2.63对于sra,主要的工作是将xrsl的第w-k-1位扩展到前面的高位。
这个可以利用取反加1来实现,不过这里的加1是加1<<(w-k-1)。
如果x的第w-k-1位为0,取反加1后,前面位全为0,如果为1,取反加1后就全是1。
最后再使用相应的掩码得到结果。
对于srl,注意工作就是将前面的高位清0,即xsra & (1<<(w-k) - 1)。
额外注意k==0时,不能使用1<<(w-k),于是改用2<<(w-k-1)。
int sra(int x, int k){int xsrl = (unsigned) x >> k;int w = sizeof(int) << 3;unsigned z = 1 << (w-k-1);unsigned mask = z - 1;unsigned right = mask & xsrl;unsigned left = ~mask & (~(z&xsrl) + z);return left | right;}int srl(unsigned x, int k){int xsra = (int) x >> k;int w = sizeof(int)*8;unsigned z = 2 << (w-k-1);return (z - 1) & xsra;}INT_MIN);}2.74对于有符号整数相减,溢出的规则可以总结为:t = a-b;如果a, b 同号,则肯定不会溢出。
如果a>=0 && b<0,则只有当t<=0时才算溢出。
如果a<0 && b>=0,则只有当t>=0时才算溢出。
计算机系统结构(第2版(课后习题答案
word 文档下载后可自由复制编辑你计算机系统结构清华第 2 版习题解答word 文档下载后可自由复制编辑1 目录1.1 第一章(P33)1.7-1.9 (透明性概念),1.12-1.18 (Amdahl定律),1.19、1.21 、1.24 (CPI/MIPS)1.2 第二章(P124)2.3 、2.5 、2.6 (浮点数性能),2.13 、2.15 (指令编码)1.3 第三章(P202)3.3 (存储层次性能), 3.5 (并行主存系统),3.15-3.15 加 1 题(堆栈模拟),3.19 中(3)(4)(6)(8)问(地址映象/ 替换算法-- 实存状况图)word 文档下载后可自由复制编辑1.4 第四章(P250)4.5 (中断屏蔽字表/中断过程示意图),4.8 (通道流量计算/通道时间图)1.5 第五章(P343)5.9 (流水线性能/ 时空图),5.15 (2种调度算法)1.6 第六章(P391)6.6 (向量流水时间计算),6.10 (Amdahl定律/MFLOPS)1.7 第七章(P446)7.3 、7.29(互连函数计算),7.6-7.14 (互连网性质),7.4 、7.5 、7.26(多级网寻径算法),word 文档下载后可自由复制编辑7.27 (寻径/ 选播算法)1.8 第八章(P498)8.12 ( SISD/SIMD 算法)1.9 第九章(P562)9.18 ( SISD/多功能部件/SIMD/MIMD 算法)(注:每章可选1-2 个主要知识点,每个知识点可只选 1 题。
有下划线者为推荐的主要知识点。
)word 文档 下载后可自由复制编辑2 例 , 习题2.1 第一章 (P33)例 1.1,p10假设将某系统的某一部件的处理速度加快到 10倍 ,但该部件的原处理时间仅为整个运行时间的40%,则采用加快措施后能使整个系统的性能提高多少?解:由题意可知: Fe=0.4, Se=10,根据 Amdahl 定律S n To T n1 (1Fe )S n 1 10.6 0.4100.64 Fe Se 1.56word 文档 下载后可自由复制编辑例 1.2,p10采用哪种实现技术来求浮点数平方根 FPSQR 的操作对系统的性能影响较大。
计算机操作系统第二版答案(郁红英)
习题二1.操作系统中为什么要引入进程的概念?为了实现并发进程之间的合作和协调,以及保证系统的安全,操作系统在进程管理方面要做哪些工作?答:(1)为了从变化的角度动态地分析研究可以并发执行的程序,真实地反应系统的独立性、并发性、动态性和相互制约,操作系统中就不得不引入“进程”的概念;(2)为了防止操作系统及其关键的数据结构,受到用户程序有意或无意的破坏,通常将处理机的执行状态分成核心态和用户态;对系统中的全部进程实行有效地管理,其主要表现是对一个进程进行创建、撤销以及在某些进程状态之间的转换控制,2.试描述当前正在运行的进程状态改变时,操作系统进行进程切换的步骤。
答:(1)就绪状态→运行状态。
处于就绪状态的进程,具备了运行的条件,但由于未能获得处理机,故没有运行。
(2)运行状态→就绪状态。
正在运行的进程,由于规定的时间片用完而被暂停执行,该进程就会从运行状态转变为就绪状态。
(3)运行状态→阻塞状态。
处于运行状态的进程,除了因为时间片用完而暂停执行外还有可能由于系统中的其他因素的影响而不能继续执行下去。
3.现代操作系统一般都提供多任务的环境,试回答以下问题。
(1)为支持多进程的并发执行,系统必须建立哪些关于进程的数据结构?答:为支持进程的并发执行,系统必须建立“进程控制块(PCB)”,PCB的组织方式常用的是链接方式。
(2)为支持进程的状态变迁,系统至少应该供哪些进程控制原语?答:进程的阻塞与唤醒原语和进程的挂起与激活原语。
(3)当进程的状态变迁时,相应的数据结构发生变化吗?答:创建原语:建立进程的PCB,并将进程投入就绪队列。
;撤销原语:删除进程的PCB,并将进程在其队列中摘除;阻塞原语:将进程PCB中进程的状态从运行状态改为阻塞状态,并将进程投入阻塞队列;唤醒原语:将进程PCB中进程的状态从阻塞状态改为就绪状态,并将进程从则色队列摘下,投入到就绪队列中。
4.什么是进程控制块?从进程管理、中断处理、进程通信、文件管理、设备管理及存储管理的角度设计进程控制块应该包含的内容。
深入理解计算机系统(第二版)家庭作业问题详解
int saturating_add(int x, int y){int w = sizeof(int)<<3;int t = x + y;int ans = x + y;x>>=(w-1);y>>=(w-1);t>>=(w-1);int pos_ovf = ~x&~y&t;int neg_ovf = x&y&~t;int novf = ~(pos_ovf|neg_ovf);return(pos_ovf & INT_MAX) | (novf & ans) | (neg_ovf & INT_MIN); }2.74对于有符号整数相减,溢出的规则可以总结为:t = a-b;如果a, b 同号,则肯定不会溢出。
如果a>=0 && b<0,则只有当t<=0时才算溢出。
如果a<0 && b>=0,则只有当t>=0时才算溢出。
不过,上述t肯定不会等于0,因为当a,b不同号时:1) a!=b,因此a-b不会等于0。
2) a-b <= abs(a) + abs(b) <= abs(TMax) + abs(TMin)=(2^w - 1)所以,a,b异号,t,b同号即可判定为溢出。
int tsub_ovf(int x, int y){int w = sizeof(int)<<3;int t = x - y;x>>=(w-1);y>>=(w-1);t>>=(w-1);return(x != y) && (y == t);}顺便整理一下汇编中CF,OF的设定规则(个人总结,如有不对之处,欢迎指正)。
t = a + b;CF: (unsigned t) < (unsigned a) 进位标志OF: (a<0 == b<0) && (t<0 != a<0)t = a - b;CF: (a<0 && b>=0) || ((a<0 == b<0) && t<0) 退位标志OF: (a<0 != b<0) && (b<0 == t<0)汇编中,无符号和有符号运算对条件码(标志位)的设定应该是相同的,但是对于无符号比较和有符号比较,其返回值是根据不同的标志位进行的。
计算机系统导论homework_2参考答案
2.1.3 Lab: Benchmarking (Optional)Benchmarking, which is the process of running standardized tests upon differing configurations to determine the speed of components or software was briefly mentioned in 2.1.1 Processor Basics. This lab will give you a greater understanding of benchmarks by having you download Fresh Diagnose, an application that allows you to analyze and benchmark your computer system. You will use the software to compare the benchmarking results of your processor with those of your classmates.Note:This lab is to be performed on Intel-based computers running Windows 95/98/NT4/2000/XP/ME.Learning Exercise:∙Download Fresh Diagnose and install it. (1102 kb download)∙Run the application.∙Click on Benchmarks on the left-hand side menu.∙Pick Processor Benchmark and click on Start on the upper-right corner of the application screen.∙Compare your results with those of your classmates.∙Try another benchmark and compare your results with those of your classmates.∙You can also explore your system's properties through the other options on the left-hand side menu.Exercise 2Question 1. Choosing MicroprocessorsThe following processors are made by Intel:A. Mobile Intel® Pentium® 4 Processor with Hyper-Threading Technology Processor speed: 3.2GHzLow power consumptionLevel 2 cache: 512KBSystem bus: 800 MHzB. Mobile Intel Pentium® 4 Processor-MProcessor speed: 2.8GHzLevel 2 512KBSystem bus: 533 MHzC. Intel Celeron®Processor speed: 2.8 GHzLevel 2 128KBSystem bus: up to 400 MHzYou may find the following resources useful:∙Intel Notebook Processors∙The CPU Scorecarda. List the processors described above by their price range (from the cheapest to the most expensive).b. List the processors described above by their performance (from the best to the worst).c. Which of the above processors would be the fastest when used for multi-media production and multi-tasking (running 10 or more applications at the same time)?Unit 1 and Unit 2 Review Materials1. Benchmarksa.With regard to computing, define the term benchmark.The comparison of disparate systems or components via a standardized set of instructions.The comparison is measured on the time it takes to execute these instructionsb.What tasks does benchmarking software perform in order to measurethe system being tested?Benchmarking software has the processor execute a series of tasks, comparing various aspects of system performance. These tasks can test anything from just the processor to video output to system bus speeds.c.How can consumers use benchmarks to help them purchase a computersystem?For a consumer, it can be difficult to compare two systems with different processor chips and video cards to find one with the optimal performance for the style of application that they will be running. Benchmarking computers can compare these two vastly differing systems in a quantifiable way, giving the consumer the ability to purchase the machine that will perform as neededd.How do benchmarks help identify slow points (bottlenecks) in thesystem?Benchmarking software can identify slow points (bottlenecks) by testing the speedsof various components and listing areas where the computer is waiting for data, andwhat is keeping the data for arriving quickly.puter Speeda.One Hz is one _____ per _____. One Hz is one cycle per secondb.Define IPS. IPS is instructions per second which is a rating of how many instructionscan be executed by a processor in a given secondc.Answer the following questions on the relationship of Hz to IPS.i.Which is a better determiner of speed: MHz or IPS? IPSis a better determiner of computer performanceii.Does a high Hz equal a high IPS, and can they beinversely proportional? Explain.A high Hz can indicate thatthe IPS is high, but they are not directly proportional, but can never beinversely proportionaliii.How is it possible for a machine with a lower clockspeed (Hz) to have a higher IPS than a machine with ahigher clock speed?An instruction can take a variable amount of cycles or partial cycles. Thus, a computer can execute instructions more quickly than another computer because of this.d.What is the relationship between the system clock and Hz? The systemclock sends out pulses at regular intervals to set up the timings for all timed systemactivities, such as determining the Hz of a processor14. RAMa.Define RAM. RAM is random access memory. It is the main storage for data, holdingthe data before and after processingb.What is the unit of measurement typically used for the speed of RAM?The speed of RAM is measured in nanosecondsc.What is SDRAM and how does it work? SDRAM is Synchronous Dynamic RAM,a type of DRAM that is fast and relatively inexpensive. It is synchronously clocked to thesystem bus. This means that RAM can send out data to the CPU for each tick of the clockd.Data on hard disk drives is accessed indirectly via the file system.i.How is data in RAM accessed? RAM is accessed directly via itsaddressii.What are the benefits of accessing RAM in this way?Accessing RAM directly increases the speed of information retrievale.With regard to RAM, what is volatility? Volatility means that when the poweris lost the data stored in RAM is also lost。
计算机系统结构(第2版(课后习题答案
word 文档下载后可自由复制编辑你计算机系统结构清华第 2 版习题解答word 文档下载后可自由复制编辑1 目录1.1 第一章(P33)1.7-1.9 (透明性概念),1.12-1.18 (Amdahl定律),1.19、1.21 、1.24 (CPI/MIPS)1.2 第二章(P124)2.3 、2.5 、2.6 (浮点数性能),2.13 、2.15 (指令编码)1.3 第三章(P202)3.3 (存储层次性能), 3.5 (并行主存系统),3.15-3.15 加 1 题(堆栈模拟),3.19 中(3)(4)(6)(8)问(地址映象/ 替换算法-- 实存状况图)word 文档下载后可自由复制编辑1.4 第四章(P250)4.5 (中断屏蔽字表/中断过程示意图),4.8 (通道流量计算/通道时间图)1.5 第五章(P343)5.9 (流水线性能/ 时空图),5.15 (2种调度算法)1.6 第六章(P391)6.6 (向量流水时间计算),6.10 (Amdahl定律/MFLOPS)1.7 第七章(P446)7.3 、7.29(互连函数计算),7.6-7.14 (互连网性质),7.4 、7.5 、7.26(多级网寻径算法),word 文档下载后可自由复制编辑7.27 (寻径/ 选播算法)1.8 第八章(P498)8.12 ( SISD/SIMD 算法)1.9 第九章(P562)9.18 ( SISD/多功能部件/SIMD/MIMD 算法)(注:每章可选1-2 个主要知识点,每个知识点可只选 1 题。
有下划线者为推荐的主要知识点。
)word 文档 下载后可自由复制编辑2 例 , 习题2.1 第一章 (P33)例 1.1,p10假设将某系统的某一部件的处理速度加快到 10倍 ,但该部件的原处理时间仅为整个运行时间的40%,则采用加快措施后能使整个系统的性能提高多少?解:由题意可知: Fe=0.4, Se=10,根据 Amdahl 定律S n To T n1 (1Fe )S n 1 10.6 0.4100.64 Fe Se 1.56word 文档 下载后可自由复制编辑例 1.2,p10采用哪种实现技术来求浮点数平方根 FPSQR 的操作对系统的性能影响较大。
计算机操作系统第二版答案
计算机操作系统第二版答案习题一1. 1. 什么是操作系统?它的主要功能是什么?什么是操作系统?它的主要功能是什么?答:操作系统是用来管理计算机系统的软、硬件资源,合理地组织计算机的工作流程,以方便用户使用的程序集合;其主要功能有进程管理、存储器管理、设备管理和文件管理功能。
管理功能。
2. 2. 2. 什么是多道程序设计技术?多道程序设计技什么是多道程序设计技术?多道程序设计技术的主要特点是什么?答:多道程序设计技术是把多个程序同时放入内存,使它们共享系统中的资源;特点:多道,即计算机内存中同时存放多道相互独立的程序;宏观上并行,是指同时进入系统的多道程序都处于运行过程中;微观上串行,是指在单处理机环境下,内存中的多道程序轮流占有CPU CPU,交替执行。
,交替执行。
3. 3. 批处理系统是怎样的一种操作系统?它的特点是什批处理系统是怎样的一种操作系统?它的特点是什么?答:批处理操作系统是一种基本的操作系统类型。
在该系统中,用户的作业被成批的输入到计算机中,然后在操作系统的控制下,用户的作业自动地执行;特点是:资源利用率高、系统吞吐量大、平均周转时间长、无交互能力。
长、无交互能力。
4. 4. 4. 什么是分时系统?什么是实时系统?什么是分时系统?什么是实时系统?试从交互性、及时性、独立性、多路性和可靠性几个方面比较分时系统和实时系统。
较分时系统和实时系统。
答:分时系统:一个计算机和许多终端设备连接,每个 答:分时系统:一个计算机和许多终端设备连接,每个用户可以通过终端向计算机发出指令,请求完成某项工作,在这样的系统中,用户感觉不到其他用户的存在,好像独占计算机一样。
计算机一样。
实时系统:对外部输入的信息,实时系统能够在规定的 实时系统:对外部输入的信息,实时系统能够在规定的时间内处理完毕并作出反应。
比较:交互性:实时系统具时间内处理完毕并作出反应。
有交互性,但人与系统的交互,仅限于访问系统中某些特定的专用服务程序。
计算机操作系统第二版课后答案 徐甲同
计算机操作系统第二版课后答案徐甲同1、在演示文稿播放过程中,当幻灯片进入和离开屏幕时,出现溶解盒状展开擦除等切换效果,是因为()。
[单选题] *A. 在一张幻灯片内部设置了播放效果B. 设置了幻灯片的切换效果(正确答案)C. 为幻灯片使用了适当的模板2、C:机器语言编写的程序执行效率最低D:不同型号的CPU具有相同的机器语言下列叙述中,错误的是______。
[单选题] *A:硬盘在主机箱内,它是主机的组成部分(正确答案)B:硬盘属于外部存储器3、在WPS文字中,如果已存在一个名为实验wps的文件,要想将它换名为NEW.docx,可以选择()命令。
[单选题] *A)另存为((正确答案)B)保存(C)全部保存(4、WPS演示文稿提供了多种(),它包含了相应的配色方案母版和字体样式等,可供用户快速生成风格统一的演示文稿。
[单选题] *A.新幻灯片B.模板(正确答案)C.配色方案5、.Windows的窗口分为类,下面()不是Windows的窗口类型。
[单选题] *A. 对话框B. 快捷菜单(正确答案)C. 文档窗口6、计算机系统软件中,最基本、最核心的软件是______。
[单选题] *A:操作系统(正确答案)B:数据库管理系统C:程序语言处理系统D:系统维护工具7、下列说法正确的是______。
[单选题] *A:进程是一段程序B:进程是一段程序的执行过程(正确答案)C:线程是一段子程序D:线程是多个进程的执行过程8、HTTP 是()。
中[单选题] *A.超文本标记语言B.超文本传送协议(正确答案)C.搜索引擎D.文件传输协议9、39.计算机网络是计算机技术和()[单选题] *A.自动化技术的结合B.通信技术的结合(正确答案)C.电缆等传输技术的结合D.信息技术的结合10、计算机中运算器的主要功能是()。
[单选题] * A.存储各种数据和程序B.传输各种信息C.进行算术运算和逻辑运算(正确答案)D.对系统各部件实行控制11、操作系统是()。
计算机操作系统第二版答案
计算机操作系统第二版答案习题一1. 什么是操作系统?它的主要功能是什么?答:操作系统是用来管理计算机系统的软、硬件资源,合理地组织计算机的工作流程,以方便用户使用的程序集合;其主要功能有进程管理、存储器管理、设备管理和文件管理功能。
2. 什么是多道程序设计技术?多道程序设计技术的主要特点是什么?答:多道程序设计技术是把多个程序同时放入内存,使它们共享系统中的资源;特点:多道,即计算机内存中同时存放多道相互独立的程序;宏观上并行,是指同时进入系统的多道程序都处于运行过程中;微观上串行,是指在单处理机环境下,内存中的多道程序轮流占有CPU,交替执行。
3. 批处理系统是怎样的一种操作系统?它的特点是什么?答:批处理操作系统是一种基本的操作系统类型。
在该系统中,用户的作业被成批的输入到计算机中,然后在操作系统的控制下,用户的作业自动地执行;特点是:资源利用率高、系统吞吐量大、平均周转时间长、无交互能力。
4. 什么是分时系统?什么是实时系统?试从交互性、及时性、独立性、多路性和可靠性几个方面比较分时系统和实时系统。
答:分时系统:一个计算机和许多终端设备连接,每个用户可以通过终端向计算机发出指令,请求完成某项工作,在这样的系统中,用户感觉不到其他用户的存在,好像独占计算机一样。
实时系统:对外部输入的信息,实时系统能够在规定的时间内处理完毕并作出反应。
比较:交互性:实时系统具有交互性,但人与系统的交互,仅限于访问系统中某些特定的专用服务程序。
它不像分时系统那样向终端用户提供数据处理、资源共享等服务。
实时系统的交互性要求系统具有连续人机对话的能力,也就是说,在交互的过程中要对用户得输入有一定的记忆和进一步的推断的能力。
及时性:实时系统对及时性的要求与分时系统类似,都以人们能够接受的等待时间来确定。
而及时系统则对及时性要求更高。
独立性:实时系统与分时系统一样具有独立性。
每个终端用户提出请求时,是彼此独立的工作、互不干扰。
深入理解计算机系统 家庭作业答案
2) a-b <= abs(a) + abs(b) <= abs(TMax) + abs(TMin)=(2^w - 1)所以,a,b异号,t,b同号即可判定为溢出。
int tsub_ovf(int x, int y){int w = sizeof(int)<<3;int t = x - y;x>>=(w-1);y>>=(w-1);t>>=(w-1);return(x != y) && (y == t);}顺便整理一下汇编中CF,OF的设定规则(个人总结,如有不对之处,欢迎指正)。
t = a + b;CF: (unsigned t) < (unsigned a) 进位标志OF: (a<0 == b<0) && (t<0 != a<0)t = a - b;CF: (a<0 && b>=0) || ((a<0 == b<0) && t<0) 退位标志OF: (a<0 != b<0) && (b<0 == t<0)汇编中,无符号和有符号运算对条件码(标志位)的设定应该是相同的,但是对于无符号比较和有符号比较,其返回值是根据不同的标志位进行的。
详情可以参考第三章节。
根据2-18,不难推导, (x'*y')_h = (x*y)_h + x(w-1)*y + y(w-1)*x。
unsigned unsigned_high_prod(unsigned x, unsigned y){int w = sizeof(int)<<3;A. false,float只能精确表示最高位1和最低位的1的位数之差小于24的整数。
所以当x==TMAX时,用float就无法精确表示,但double是可以精确表示所有32位整数的。
计算机系统结构(第2版(课后习题答案.
浮点数据表示;不透明(系统结构)
I/O 系统是采用通道方式还是 I/O 处理机方式;不透明
数据总线宽度;透明(组成)
阵列运算部件;透明(组成)
通道是采用结合型的还是独立型的;透明(组成)
PDP-11 系列中的单总线结构;不透明(系统结构)
果 FPSQR 操作的 CPI 也为 4.0,重新计算等效 CPI。
解:
n
CPI (CPI i
i 1
Ii
)
IC
等效 CPI=100´2%+4´23%+1.33´75%
=3.92
等效 CPI2=4´25%+1.33´75%
=2.00
1.1
解释下列术语
层次结构,计算机系统结构,计算机组成,计算机实现,透明性,由上而下设计,由下而
钟周期。
CPUA:采用一条比较指令来设置相应的条件码,由紧随其后的一条转移指令对此条件码进行
9
测试,以确定是否进行转移。显然实现一次条件转移要执行比较和测试两条指令。条件转
移指令占总执行指令条数的 20%。由于每条转移指令都需要一条比较指令,所以比较指令也
将占 20%。
CPUB 采用比较功能和判别是否实现转移功能合在一条指令的方法,这样实现一条件转移就只
浮点数据,×,P4
通道与 I/O 处理机,×,P4
总线宽度,√,
阵列运算部件,×,
结合型与独立型通道,√,
单总线,√,
访问保护,×,
中断,×,
指令控制方式,√,
堆栈指令,×,
最小编址单位,×,
Cache 存储器,√,
1.8
从机器(汇编)语言程序员看,以下哪些是透明的?
深入理解计算机系统答案
深入理解计算机系统答案【篇一:深入理解计算机系统笔记】(1)对于一个无符号数字 x, 截断它到 k 位的结果就相当于计算 x mod 2^k.(2)在大多数的机器上 ,整数乘法指令相当地慢 ,需要 12 或者更多的始终周期 ,然而其他整数运算-例如加法、减法、位移运算和移位-只需要 1 个时钟周期 .因此 ,编译器使用的一项重要的优化就是试着使用移位和加法运算的组合来代替乘以常数因子的乘法.(3)在大多数的机器上 ,整数除法要比整数乘法更慢-需要 30 或者更多的始终周期 .除以 2 的幂也可以用移位运算来实现 ,只不过我们用的是右移 ,而不是左移 .对于无符号和二进制补码数 ,分别使用逻辑移位和算术移位来达到目的 .1. 注意系统的分类:主流的 ia32( 也就是 x86) ,以及 x86-64( 也就是x64) ,还有种 intel 的与原 32 位系统不兼容的 ia64 。
2. 编译系统由预处理器,编译器,汇编器和链接器组成。
3.单指令多数据并行称为 simd 并行,其扩展为 sse 指令集。
4.x64 上 long 为 8 字节,指针也为 8 字节。
5.无符号数右移必须采用逻辑右移,而有符号数一般采用算术右移。
6.有符号数遇见无符号数会默认强转为无符号数。
7.short 转为 unsigned 时,是先扩展大小再符号转换。
8. 补码非的计算:从左到右将第一个为 1 的位前的所有位取反。
9.负数的补码移位向下舍入。
10.正浮点数能使用整数排序函数来进行排序。
11.浮点加法和乘法不具备结合性,浮点乘法在加法上不具备分配性。
12.预处理器扩展源代码,然后编译器生成源代码的文本汇编代码,汇编器转成二进制汇编码,链接器生成exe 或 dll 或 lib 。
13.寄存器可以保存地址也可以保存值。
注意汇编中的加括号表示为取该地址指向的值,如 (%eax) 指 %eax 中保存的地址指向的值。
14.传送指令的两个操作符不能都指向存储器。
深入理解计算机系统答案(超高清电子版)
深⼊理解计算机系统答案(超⾼清电⼦版)Computer Systems:A Programmer’s Perspective Instructor’s Solution Manual1Randal E.BryantDavid R.O’HallaronDecember4,20032Chapter1Solutions to Homework ProblemsThe 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.1Chapter1:A Tour of Computer Systems1.2Chapter2:Representing and Manipulating InformationProblem2.40Solution:This exercise should be a straightforward variation on the existing code.2CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS1011void show_double(double x)12{13show_bytes((byte_pointer)&x,sizeof(double));14}code/data/show-ans.c 1int is_little_endian(void)3/*MSB=0,LSB=1*/4int x=1;56/*Return MSB when big-endian,LSB when little-endian*/7return(int)(*(char*)&x);8}1.2.CHAPTER2:REPRESENTING AND MANIPULATING INFORMATION3 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 The above code peforms a right shift of a word in which all bits are set to1.If the shift is arithmetic,the resulting word will still have all bits set to1.Problem2.45Solution:This problem illustrates some of the challenges of writing portable code.The fact that1<<32yields0on some32-bit machines and1on others is common source of bugs.A.The C standard does not de?ne the effect of a shift by32of a32-bit datum.On the SPARC(andmany other machines),the expression x</doc/dde1f034f111f18583d05a59.html pute beyond_msb as2<<31.C.We cannot shift by more than15bits at a time,but we can compose multiple shifts to get thedesired effect.Thus,we can compute set_msb as2<<15<<15,and beyond_msb as set_msb<<1.Problem2.46Solution: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 byte0fromword0xFF,we will get255,rather than.B.The following code uses a well-known trick for using shifts to isolate a particular range of bits and toperform sign extension at the same time.First,we perform a left shift so that the most signi?cant bit of the desired byte is at bit position31.Then we right shift by24,moving the byte into the proper position and peforming sign extension at the same time. 4CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 3int left=word<<((3-bytenum)<<3);4return left>>24;5}Problem2.48Solution:This problem lets students rework the proof that complement plus increment performs negation.We make use of the property that two’s complement addition is associative,commutative,and has additive/doc/dde1f034f111f18583d05a59.html ing C notation,if we de?ne y to be x-1,then we have?y+1equal to-y,and hence?y equals -y+1.Substituting gives the expression-(x-1)+1,which equals-x.Problem2.49Solution:This problem requires a fairly deep understanding of two’s complement arithmetic.Some machines only provide one form of multiplication,and hence the trick shown in the code here is actually required to perform that actual form.As seen in Equation2.16we have.The?nal term has no effect on the-bit representation of,but the middle term represents acode/data/uhp-ans.c Problem2.50Solution:1.2.CHAPTER2:REPRESENTING AND MANIPULATING INFORMATION5A.:x+(x<<2)B.:x+(x<<3)C.:(x<<4)-(x<<1)D.:(x<<3)-(x<<6)Problem2.51Solution:Bit patterns similar to these arise in many applications.Many programmers provide them directly in hex-adecimal,but it would be better if they could express them in more abstract ways.A..((1<B..((1<Problem2.52Solution:Byte extraction and insertion code is useful in many contexts.Being able to write this sort of code is an important skill to foster.code/data/rbyte-ans.c Problem2.53Solution:These problems are fairly tricky.They require generating masks based on the shift amounts.Shift value k equal to0must be handled as a special case,since otherwise we would be generating the mask by performing a left shift by32.6CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 1unsigned srl(unsigned x,int k)2{3/*Perform shift arithmetically*/4unsigned xsra=(int)x>>k;5/*Make mask of low order32-k bits*/6unsigned mask=k?((1<<(32-k))-1):?0;78return xsra&mask;9}code/data/rshift-ans.c 1int sra(int x,int k)2{3/*Perform shift logically*/4int xsrl=(unsigned)x>>k;5/*Make mask of high order k bits*/6unsigned mask=k??((1<<(32-k))-1):0;78return(x<0)?mask|xsrl:xsrl;1.2.CHAPTER2:REPRESENTING AND MANIPULATING INFORMATION7B.(a)For,we have,,code/data/?oatge-ans.c 1int float_ge(float x,float y)2{3unsigned ux=f2u(x);4unsigned uy=f2u(y);5unsigned sx=ux>>31;6unsigned sy=uy>>31;78return9(ux<<1==0&&uy<<1==0)||/*Both are zero*/10(!sx&&sy)||/*x>=0,y<0*/11(!sx&&!sy&&ux>=uy)||/*x>=0,y>=0*/12(sx&&sy&&ux<=uy);/*x<0,y<0*/13},8CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS This 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 the range of values that can be represented.Description Extended precisionValueSmallest denorm.Largest norm.Problem2.59Solution:We have found that working through?oating point representations for small word sizes is very instructive. Problems such as this one help make the description of IEEE?oating point more concrete.Description8000Smallest value4700Largest denormalized———1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS91/*Compute2**x*/2float fpwr2(int x){4unsigned exp,sig;5unsigned u;67if(x<-149){8/*Too small.Return0.0*/9exp=0;10sig=0;11}else if(x<-126){12/*Denormalized result*/13exp=0;14sig=1<<(x+149);15}else if(x<128){16/*Normalized result.*/17exp=x+127;18sig=0;19}else{20/*Too big.Return+oo*/21exp=255;22sig=0;23}24u=exp<<23|sig;25return u2f(u);26}10CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS int decode2(int x,int y,int z){int t1=y-z;int t2=x*t1;int t3=(t1<<31)>>31;int t4=t3?t2;return t4;}Problem3.32Solution:This code example demonstrates one of the pedagogical challenges of using a compiler to generate assembly code examples.Seemingly insigni?cant changes in the C code can yield very different results.Of course, students will have to contend with this property as work with machine-generated assembly code anyhow. They will need to be able to decipher many different code patterns.This problem encourages them to think in abstract terms about one such pattern.1movl8(%ebp),%edx x2movl12(%ebp),%ecx y3movl%edx,%eax4subl%ecx,%eax result=x-y5cmpl%ecx,%edx Compare x:y6jge.L3if>=goto done:7movl%ecx,%eax8subl%edx,%eax result=y-x9.L3:done:A.When,it will compute?rst and then.When it just computes.B.The code for then-statement gets executed unconditionally.It then jumps over the code for else-statement if the test is false.C.then-statementt=test-expr;if(t)goto done;else-statementdone:D.The code in then-statement must not have any side effects,other than to set variables that are also set1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS11Problem3.33Solution:This problem requires students to reason about the code fragments that implement the different branches of a switch statement.For this code,it also requires understanding different forms of pointer dereferencing.A.In line29,register%edx is copied to register%eax as the return value.From this,we can infer that%edx holds result.B.The original C code for the function is as follows:1/*Enumerated type creates set of constants numbered0and upward*/2typedef enum{MODE_A,MODE_B,MODE_C,MODE_D,MODE_E}mode_t;34int switch3(int*p1,int*p2,mode_t action)5{6int result=0;7switch(action){8case MODE_A:12case MODE_B:13*p2+=*p1;14result=*p2;15break;16case MODE_C:17*p2=15;18result=*p1;19break;20case MODE_D:21*p2=*p1;22/*Fall Through*/23case MODE_E:24result=17;25break;26default:27result=-1;28}29return result;30}Problem3.34Solution:This problem gives students practice analyzing disassembled code.The switch statement contains all the features one can imagine—cases with multiple labels,holes in the range of possible case values,and cases that fall through.12CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 1int switch_prob(int x)2{3int result=x;45switch(x){6case50:7case52:8result<<=2;9break;10case53:11result>>=2;15/*Fall through*/16case55:17result*=result;18/*Fall through*/19default:20result+=10;21}2223return result;24}code/asm/varprod-ans.c 1int var_prod_ele_opt(var_matrix A,var_matrix B,int i,int k,int n) 2{3int*Aptr=&A[i*n];4int*Bptr=&B[k];5int result=0;6int cnt=n;78if(n<=0)9return result;1011do{12result+=(*Aptr)*(*Bptr);13Aptr+=1;14Bptr+=n;1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS13 16}while(cnt); 1718return result;19}code/asm/structprob-ans.c 1typedef struct{2int idx;3int x[4];4}a_struct;14CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 1/*Read input line and write it back*/ 2/*Code will work for any buffer size.Bigger is more time-efficient*/ 3#define BUFSIZE644void good_echo()5{6char buf[BUFSIZE];7int i;8while(1){9if(!fgets(buf,BUFSIZE,stdin))10return;/*End of file or error*/11/*Print characters in buffer*/12for(i=0;buf[i]&&buf[i]!=’\n’;i++)13if(putchar(buf[i])==EOF)14return;/*Error*/15if(buf[i]==’\n’){16/*Reached terminating newline*/17putchar(’\n’);18return;19}20}21}An alternative implementation is to use getchar to read the characters one at a time.Problem3.38Solution:Successfully mounting a buffer over?ow attack requires understanding many aspects of machine-level pro-grams.It is quite intriguing that by supplying a string to one function,we can alter the behavior of another function that should always return a? xed value.In assigning this problem,you should also give students a stern lecture about ethical computing practices and dispell any notion that hacking into systems is a desirable or even acceptable thing to do.Our solution starts by disassembling bufbomb,giving the following code for getbuf: 1080484f4:280484f4:55push%ebp380484f5:89e5mov%esp,%ebp480484f7:83ec18sub$0x18,%esp580484fa:83c4f4add$0xfffffff4,%esp680484fd:8d45f4lea0xfffffff4(%ebp),%eax78048500:50push%eax88048501:e86a ff ff ff call804847098048506:b801000000mov$0x1,%eax10804850b:89ec mov%ebp,%esp11804850d:5d pop%ebp12804850e:c3retWe can see on line6that the address of buf is12bytes below the saved value of%ebp,which is4bytes1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS15 of%ebp,and the address of the start of the buffer.To determine the relevant values,we run GDB as follows:1.First,we set a breakpoint in getbuf and run the program to that point:(gdb)break getbuf(gdb)runComparing the stopping point to the disassembly,we see that it has already set up the stack frame.2.We get the value of buf by computing a value relative to%ebp:(gdb)print/x(%ebp+12)This gives0xbfffefbc.3.We?nd the saved value of register%ebp by dereferencing the current value of this register:(gdb)print/x*$ebpThis gives0xbfffefe8.4.We?nd the value of the return pointer on the stack,at offset4relative to%ebp:(gdb)print/x*((int*)$ebp+1)This gives0x8048528We can now put this information together to generate assembly code for our attack:1pushl$0x8048528Put correct return pointer back on stack2movl$0xdeadbeef,%eax Alter return value3ret Re-execute return4.align4Round up to125.long0xbfffefe8Saved value of%ebp6.long0xbfffefbc Location of buf7.long0x00000000PaddingNote that we have used the.align statement to get the assembler to insert enough extra bytes to use up twelve bytes for the code.We added an extra4bytes of0s at the end,because in some cases OBJDUMP would not generate the complete byte pattern for the data.These extra bytes(plus the termininating null byte)will over?ow into the stack frame for test,but they will not affect the program behavior. Assembling this code and disassembling the object code gives us the following:10:6828850408push$0x804852825:b8ef be ad de mov$0xdeadbeef,%eax3a:c3ret4b:90nop Byte inserted for alignment.5c:e8ef ff bf bc call0xbcc00000Invalid disassembly.611:ef out%eax,(%dx)Trying to diassemble712:ff(bad)data16CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS From this we can read off the byte sequence:Problem3.39Solution:This problem is a variant on the asm examples in the text.The code is actually fairly simple.It relies on the fact that asm outputs can be arbitrary lvalues,and hence we can use dest[0]and dest[1]directly in the output list.code/asm/asmprobs-ans.c Problem3.40Solution:For this example,students essentially have to write the entire function in assembly.There is no(apparent) way to interface between the?oating point registers and the C code using extended asm.code/asm/fscale.c1.4.CHAPTER4:PROCESSOR ARCHITECTURE17 1.4Chapter4:Processor ArchitectureProblem4.32Solution:This problem makes students carefully examine the tables showing the computation stages for the different instructions.The steps for iaddl are a hybrid of those for irmovl and OPl.StageFetchrA:rB M PCvalP PCExecuteR rB valEPC updateleaveicode:ifun M PCDecodevalB RvalE valBMemoryWrite backR valMPC valPProblem4.34Solution:The following HCL code includes implementations of both the iaddl instruction and the leave instruc-tions.The implementations are fairly straightforward given the computation steps listed in the solutions to problems4.32and4.33.You can test the solutions using the test code in the ptest subdirectory.Make sure you use command line argument‘-i.’。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
return (x»l) == -1;
}
2・63
对于sra,主要的工作是将xrsl的第w-k-1时展到前面的高位。
这个可以利用取反加1来实现,不过这里的加1是加1«(w-k-1)0
如果x的第w-k-1位为0,取反加1后,前面位全为0,如果为1,取反加1后就全是!<> 最后再使用相应的掩码得到结果。
2.55-2.57
略
2・58
intis_little_endian(){
inta = 1;
return*((char*)&a);
}
2・59
(x&OxFF) |(y&~OxFF)
2・60
unsignedreplace_byte(unsignedx,unsignedcharbzinti)
{
return(x&~(OxFF<<(i<<3) ) )| (b « (i«3));
}
2・61
A・!〜x
B・!x
C・!〜(x>> ( (sizeof (int) -1) «3))
D・!(x&OxFF)
注意,英文版中c是最低字节,D是最高字节。中文版恰好反过来了。这里是按中文版来做 的。
2・62
这里我感觉应该是英文版对的,int_shifts_ _are_arithmetic()
intint_shif ts_are_arithmetic(){
2・67
A.32位机器上没有走义移位32次。
B・beyond__msb变为2«31O
C・走义a = 1«15; a«=15; set_msb = a«l; beyond_msb = a«2;
2・68
感觉中文版有点问题,注释和函数有点对应不上,于是用英文版的了。
个人猜想应该是让X的最]氐n位变
intlower_one_mask(intn) {
CF: (a<0 && b>=0)| |( (a<0 == b<0) && t<0)退位标志
OF: (a<0 != b<0) && (b<0 == t<0)
汇编中,无符号和有符号运算对条彳牛码(标志位)的设走应该是相同的,但是对于无符号比较和有符号比较,其返回值是根据不同的标志位进行的。
unsigned mask = z -1;
unsigned right = mask&xsrl;
unsigned left = ~mask&(~(z&xsrl) + z);returnleftright;
}
intsrl(unsigned x,intk){
intxsra =(int)x » k;
intw =sizeof(int)*8;
x»=(w-l);
y»=(w-l);
t»=(w-l);
intpos_ovf = ~x&〜y&t;
intneg_ovf =
intnovf =〜(pos_ovf|neg_ovf);
return(pos_ovf&工NT_MAX) | (novf&ans) | (neg_ovf&INT_MIN);
}
t=a-b;
A・得至Ij的结果是unsignedf而并非扩展为signed的结果。
B•使用int,将待抽取字节左移到最高字节,再右移到副氐字节即可。intxbyte(unsigned word,intbytenum){
intret = word « ((3-bytenum)«3);
returnret »24;
}
return(2« (n-1) )-1;
}
2・69
unsignedrotate_right(unsignedxfintn){
intw =sizeof(unsigned)*8;
return(x»n)|(x<< (w-n-1) «1);
}
2・70
这一题是看X的值是否在-2A(n-l)到2八(n-l)- 1之间。
对于srl,注意工作就是将前面的高位清0 ,即xsra& (1«(w-k)- 1)o额外注意k==0时,不能使用(w-k),于是改用2«(w-k-1)0intsra(intxzintk) {
intxsrl = (unsigned) x » k;
intw =sizeof(int)<< 3;
unsigned z2
A.size_t是无符号整数,因此左边都会先转换为无符号整数,它肯走是大于等于0的。
£・半!J断条彳牛改为if (maxbytes> 0 &&max by tes >= sizeof (val))
2・73
请先参考2.74题。
可知:t=a+b时,如果a , b异号(或者存在0 ),则肯走不会溢出。
如果x满足这个条件,则其第n-1位就是符号位。如果该位为0,则前面的w-n位均为0 ,如果该位为1,则前面的w-n位均为lo所以本质是判断,x的高w-n+1位是否为C或者 为-1。
intfits_bits(intxfintn) {
x »= (n-1);
return!x | |! (~x);
}
2・71
10 000000••该如何让每一位都为lo于是便想到了二进扩展。先是x右移1位再W原x进行或f变成1100000.・・,再让结果右移2位和原结果或r变成11110000.・・,最后到16位f^11111111. . .0intleftmost one(unsigned x){
1);
8);
returnxA(x»l);
(x »4);
xA=
(x » 2);
xA=
(x » 1);
return! (x&l);
}
X的每个位进行异或,如果为0就说明是偶数个1,如果为1就是奇数个1。
那么可以想到折半缩小规模。最后一句也可以是return(汀1)&1
2・66
根据提示想到利用或运算,将最高位的1或到比它低的每一位上,忽然想如果X就是
如果a,b均大于等于0,则t<0就是正溢出,如果a,b均/」\于0,则t>=0就是负溢出。
于是,可以利用三个变量来表示是正溢出,负溢出还是无溢出。
intsaturating_add(intx,inty) {
intw =sizeof(int)«3;
intt = x + y;
intans = x + y;
unsigned z =2« (w-k-1);
return(z-1)&xsra;
}
2・64
intany_even_one(unsigned x){
return!!(x&(0x55555555));
2・65
inteven
ones(unsigned x) {
xA=
(x »16);
xA=
(x » 8);
xA=