CSAPP Computer System A Programmer Perspective

同一个“数”绝对值的和

一个w位的数,最高位为1,解析为无符号数、无符号数后,两个数的绝对值的和为2^w。
例如:
1011,解析为无符号数为11,有符号数为-5,绝对值相加的和为16
在这里插入图片描述

2.3、整数的运算

2.3.1 无符号加法

两个w位的无符号数x,y相加,如果产生溢出,溢出到w+1位,此时该位值为1。

此时,舍弃溢出位后的实际的值为 x+y-2^w (w+1位的值为2^w)
例:4位无符号数,9(1001) 和10(1010),不考虑溢出,相加结果为19(10011),而去除溢出位后的结果为3。

 1001
 1010
--------
10011

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

C语言中如何判断无符号数溢出

在这里插入图片描述
无符号数加法发生溢出时,结果肯定小于两个加数中的任意一个
(x+y-2^w = x+(y-2^w) = y+(x-2^w) ,一个数加上一个负数,数变小)

()补码数相加

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
正数相加溢出,溢出后的结果为负数,负数的大小是多少?

负溢出

在这里插入图片描述

在这里插入图片描述

溢出

两个正数,相加结果为负,表示发生了正溢出

两个负数,相加结果为正,表示发生了负溢出

在这里插入图片描述

加法逆元(相反数)

在这里插入图片描述
x + x’ = 0,称x’为x的逆元(相反数)

x + x' = 2^w = 0

前面的例子中255+1导致溢出,结果同样为0

在这里插入图片描述
x>=0时,x逆元 x' = 2^w-x

有符号数的逆元

在这里插入图片描述

经典计算机操作系统教材第三版,详细内容可见亚马逊。 https://www.amazon.com/Computer-Systems-Programmers-Perspective-Engineering/dp/0134123832/ref=sr_1_2?ie=UTF8&qid=1541476471&sr=8-2&keywords=computer+systems+a+programmer's+perspective Computer systems: A Programmer’s Perspective explains the underlying elements common among all computer systems and how they affect general application performance. Written from the programmer’s perspective, this book strives to teach readers how understanding basic elements of computer systems and executing real practice can lead them to create better programs. Spanning across computer science themes such as hardware architecture, the operating system, and systems software, the Third Edition serves as a comprehensive introduction to programming. This book strives to create programmers who understand all elements of computer systems and will be able to engage in any application of the field--from fixing faulty software, to writing more capable programs, to avoiding common flaws. It lays the groundwork for readers to delve into more intensive topics such as computer architecture, embedded systems, and cyber security. This book focuses on systems that execute an x86-64 machine code, and recommends that programmers have access to a Linux system for this course. Programmers should have basic familiarity with C or C++. Personalize Learning with MasteringEngineering MasteringEngineering is an online homework, tutorial, and assessment system, designed to improve results through personalized learning. This innovative online program emulates the instructor’s office hour environment, engaging and guiding students through engineering concepts with self-paced individualized coaching With a wide range of activities available, students can actively learn, understand, and retain even the most difficult concepts.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

java硕哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值