算术溢出与算术进位 [英] Arithmetic Overflow vs. Arithmetic Carry

查看:177
本文介绍了算术溢出与算术进位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的演讲幻灯片中的一个给出了算术溢出的例子,并在ARM芯片中引入了条件分支标志的主题,引用如下:


    V(溢出)
    - 7FFFFFFF + 1

    (进位)
    - FFFFFFFF + 1


假设为了举例,地址只能容纳8个字节。所以对我来说,似乎喜欢加1到7FFFFFFF给出80000000.我认为80000000仍然适合8字节的地址。



为什么这是一个算术溢出?这张幻灯片是否是错误的?或者是我的理解存在缺陷?



感谢您的回应

  • 当寄存器无法正确地将结果表示为有符号值(您溢出到符号位中)时,溢出标志被置位。

  • 如果寄存器无法正确表示结果为无符号值(不需要符号位),则会设置进位标志。

    One of my lecture slides gives an example of arithmetic overflow and carry in a topic for conditional branching flags on an ARM chip, quoted below:

    • V (overflow) -  7FFFFFFF+1
    • C (carry) -  FFFFFFFF+1

    Presumably for the sake of the example, the address can only hold 8 bytes. So to me, it seems likes adding 1 to 7FFFFFFF gives 80000000. I thought 80000000 would still fit into an 8-byte address.

    Why is this an arithmetic overflow? Is it the wrong way around on the slide? Or is my understanding flawed?

    Thanks for any responses

    解决方案

    • Overflow flags get set when the register cannot properly represent the result as a signed value (you overflowed into the sign bit).
    • Carry flags are set when the register cannot properly represent the result as an unsigned value (no sign bit required).

    这篇关于算术溢出与算术进位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆