如何正确地做 ADD/SUB 有符号或无符号整数? [英] How to do ADD/SUB signed or unsigned integer correctly?

查看:13
本文介绍了如何正确地做 ADD/SUB 有符号或无符号整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到 ARM 上有一个 ADD 指令,它对 signedunsigned int 都有效吗?当指令以 S 后缀指定时,某些状态标志应该不同,对吧?如设置溢出(V)标志.我想知道是否有另一个版本的 ADD/SUB 来处理其中一个整数.

I saw there is an ADD instruction on ARM, does it work for both signed and unsigned int? Some status flags should be different when the instruction is specified with S suffix, right? Such as setting overflow (V) flag. I am wondering is there another version of ADD/SUB to handle one of the integer.

推荐答案

补码表示有符号加法和无符号加法没有区别.s 位确定是否修改了任何标志,如果修改,则进位是无符号溢出/借位,v 是有符号溢出/借位.这在 ARMs 文档中都有描述.

Twos complement means there is no difference between signed and unsigned addition. The s bit determines whether any flags are modified or not IF modified, then carry is the unsigned overflow/borrow and v is the signed overflow/borrow. This is all described in ARMs documentation.

这篇关于如何正确地做 ADD/SUB 有符号或无符号整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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