会做一对符号和无符号数的算术运算是合法的吗? [英] would doing arithmetic operation on a pair of signed and unsigned numbers be legal?

查看:145
本文介绍了会做一对符号和无符号数的算术运算是合法的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我比一半以上通过学习装配和我熟悉如何符号和无符号整数,是位psented $ P $的概念,我知道它似乎一个奇怪的问题,它的答案是pretty明显,但如果我使用类似除了算术运算想知道有意义的一对数字的其中一人被视为签字,另一个符号,我一直认为像下面,将产生多个例子一个正确的结果:

I'm more than half way through learning assembly and I'm familiar with the concept of how signed and unsigned integers are presented in bits, I know that it might seem a weird question of which the answer would be pretty obvious, but I'm wondering if using an arithmetic operation like addition makes sense for a pair of numbers that one of them is considered signed and the other one unsigned, I've thought of multiple examples like below that will yield a correct result:

10000001(1字节的整数和无符号的考虑,相当于129)结果
+结果
11111111(1字节的整数,并认为符号(2的补体系统),相当于-1)

10000001 (1-byte integer and considered unsigned, equivalent to 129)
+
11111111 (1-byte integer and considered signed(two's complement system), equivalent to -1)

千万(1字节的整数和逻辑等价的无符号128)

10000000 (1-byte integer and in unsigned logic equivalent to 128)

现在,如果上限值是AL注册,我们有以下指令code(气格式):

Now if the upper value was in AL register and we had the following instruction code(in GAS format):

addb -1, %al

然后EFLAGS操作的已经完成后会通知实际上并没有发生溢出和寄存器将被设置进位标志(CF)也许是因为有一无符号数溢出方面溢出标志(OF) EFLAGS寄存器应参考。所以,我很困惑,如果做这样的事情永远是明智的。

then the carry flag(CF) of EFLAGS register will be set after the operation's been done and would inform of an overflow that actually has not happened and maybe because there's one unsigned number in terms of an overflow the overflow flag(OF) of EFLAGS register should be referenced. So I'm confused if doing such thing is ever sensible.

推荐答案

我发现这很不错 文章 的上是阅读文章后,我最关心的,答案是明确的问题

这篇关于会做一对符号和无符号数的算术运算是合法的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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