csapp_3rd_2.13

本文详细探讨了在补码表示下,不同数值相加时可能会出现的溢出情况。内容涉及正溢出和负溢出的定义,以及当w位的系统无法容纳w+1位的运算结果时,如何通过位模式来理解溢出的现象。文章通过实例解释了如何确定溢出后的位模式,并分析了位权重的解释变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

公式2.13的理解:

设:-2^{w-1} \leq x,y \leq 2^{w-1}-1,则:-2^{w} \leq x+y \leq 2^{w}-2

(1) 若 -2^{w-1} \leq x+y \leq 2^{w-1}-1,则 x+_w^t y = x+y,无正、负溢出。

 

(2) 若 2^{w-1} \leq x+y,则 2^{w-1} \leq x+y \leq 2^{w-1}-2 < 2^w

那么这个时候(仍然是补码的情况下)需要 w+1 位才能表示出x+y的值,设这个位模式是:

(z_{w}=0,z_{w-1}=1,z_{w-2},...,z_1,z_0)

可以确定z_w=0, z_{w-1}=1;w-2,...,0 位的值是不确定的。

 x+y=0*2^w + 2^{w-1}+\sum_{i=0}^{w-2}z_i2^i

但是事实上,系统并没有给x+y分配w+1位的空间,仍然是w位的空间。此时,x+y出现了正溢出,z_w不会出现。

即x+y的位模式是:

(z_{w-1}=1,z_{w-2},...,z_1,z_0)

则此时:

x+_w^t y = -2^{w-1} + \sum_{i=0}^{w-2}z_i2^i

z_{w-1}位的权重解释-2^{w-1},剩余位的解释不变。

x+_w^t y = x+y-2^w

 

(3) 若 -2^{w} \leq x+y < -2^{w-1}

那么这个时候(仍然是补码的情况下)需要 w+1 位才能表示出x+y的值,设这个位模式是:

(z_{w}=1,z_{w-1}=0,z_{w-2},...,z_1,z_0)

可以确定z_w=1, z_{w-1}=0;w-2,...,0 位的值是不确定的。因为x+y小于0,则z_w=1;如果z_{w-1}=1的话,即x+y=-2^{w}+2^{w-1}+\sum_{i=0}^{w-2}z_i2^i=-2^{w-1}+\sum_{i=0}^{w-2}z_i2^i>-2^{w-1}

z_{w-1}=0

所以 x+y=-2^{w}+0*2^{w-1}+\sum_{i=0}^{w-2}z_i2^i=-2^w+\sum_{i=0}^{w-2}z_i2^i

但是事实上,系统并没有给x+y分配w+1位的空间,仍然是w位的空间。此时,x+y出现了负溢出,z_w不会出现。

即x+y的位模式是:

(z_{w-1}=0,z_{w-2},...,z_1,z_0)

则此时:

x+_w^t y = 0*(-2^{w-1}) + \sum_{i=0}^{w-2}z_i2^i= \sum_{i=0}^{w-2}z_i2^i

x+_w^t y = x+y+2^w

最新的第三版,无水印版本 Everything you need to know to succeed in the programming interview and get the job you want Whether you are a veteran programmer seeking a new position or a whiz kid starting your career, interviewing for a programming job requires special preparation. The interview is likely to consist of an hour-long interactive oral exam in computers, programming, and logic. This helpful guide will give you the tools necessary to breeze through the test and make a lasting impression that will get you a top-dollar offer! Mongan and Suojanen take you step-by-step through the same problems that they were asked on technical interviews. These veterans use their experience with the technical interview process to prepare you for any situation. With their help, you’ll gain critical interviewing skills such as how to ask effective questions, how to best approach a problem, and what to do when you get stuck. Integrated throughout the book are problems taken from real interviews at top computer companies, followed by an in-depth analysis and explanation of the thought process leading to solutions. By focusing on techniques and not just answers, you’ll be able to apply what you learn to the wide variety of problems you will face during an interview. The problems included in this book will challenge your programming skills and help you ace the programming interview! Problem types include: <UL> <LI>Programming problems with emphasis on data structures and recursion <LI>Logic puzzles, counting and measuring problems, and spatial reasoning <LI>Knowledge-based problems that cover today’s most important technologies </UL>
### CSAPP Lab1 指导教程与资源 #### 关于CSAPP Lab1的介绍 CSAPP (Computer Systems: A Programmer&#39;s Perspective) 是一门深入讲解计算机系统的课程,其Lab1主要帮助学生理解并实践计算机系统的基础概念。通过完成这一实验,可以初步掌握计算机系统的基本知识以及各种类型的数据表示[^3]。 #### 获取CSAPP Lab1所需资源的方法 对于想要获取CSAPP Lab1指导教程及相关资源的学生来说,可以从北京邮电大学(BUPT)提供的计算机系统基础实验资源入手。这些资源不仅有助于顺利完成CSAPP Lab1的任务,还能让学生更好地理解和应用Linux操作系统中的基本命令和操作[^2]。 具体而言,该项目位于GitCode平台上,提供了全面而详细的文档和支持文件来辅助学习者进行有效的自我训练。访问链接如下: - **项目地址**: [https://gitcode.com/open-source-toolkit/ceabc](https://gitcode.com/open-source-toolkit/ceabc)[^1] 此外,在准备实验环境方面,建议配置满足最低硬件条件的工作站,并安装必要的虚拟化软件如VirtualBox或Vmware版本号需高于等于11,同时准备好合适的Linux发行版镜像,比如Ubuntu 16.04 LTS 或优麒麟 64位版本。开发工具的选择上则推荐使用Visual Studio 2010及以上版本或者CodeBlocks 64位版本;当然也可以采用vi/vim/gedit搭配GCC来进行编程练习。 #### 如何利用上述资源有效开展CSAPP Lab1的学习? 为了最大化地发挥所获得资料的价值,应当仔细阅读官方给出的操作指南,按照指示搭建好相应的软硬件平台之后再逐步尝试解答给定的问题集。在整个过程中遇到困难时不妨多查阅一些网络上的开源社区讨论帖或是向老师同学求助交流心得经验。 ```bash # 安装必要依赖项 sudo apt-get update && sudo apt-get install build-essential git vim gedit gcc make ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值