从一个较小的一个减去一个大的无符号二进制数 [英] Subtracting a large unsigned binary number from a smaller one

查看:1423
本文介绍了从一个较小的一个减去一个大的无符号二进制数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要带一台电脑的组织和汇编语言课程。我们实验室的笔试部分,本周有有我难倒它的问题。读取问题...

I'm taking a computer organization and assembly language course. The written part of our lab this week has a question on it that has me stumped. The question reads...

减去以下的无符号二进制数(显示借用和溢出位)。不要转换成二进制补码。

 0101 0111 1101
-1110 1011 0110
 --------------

我知道答案是的 -1001 0011 1001 ,但我有一个困难时期试图找出如何借用实际,采取更大的数量,并从它减去执行此减法较小的数字并显示我的工作。我从我已反转的问题,而是一个小数目减去大量时的整个生命中减去从较大数目的较小的数目,并在结果的前面加一个负号。我问教授,他说,他希望这个问题得到解决,这是写的方式。我不允许通过减去大量较小的数量和否定就像我通常会解决这个问题。我还没有从一个较小的一个减去一个较大的无符号二进制数的能找到任何在线的例子。

I realize that the answer is -1001 0011 1001 but I'm having a hard time trying to figure out how to borrow to actually perform this subtraction by taking the larger number and subtracting it from the smaller number and show my work. My whole life when subtracting a large number from a small number I have reversed the problem and instead subtracted the smaller number from the larger number and added a negative sign in front of the result. I asked the professor and he says that he wants the problem solved the way that it is written. I am not allowed to solve this by subtracting the smaller number from the larger number and negating like I normally would. I haven't been able to find any examples online of subtracting a larger unsigned binary number from a smaller one.

我真的AP preciate,如果有人可以给我描述了如何在这种情况下执行减法。

I would really appreciate it if someone could describe to me how to perform subtraction in this scenario.

更新:
@Alex是正确的。这位教授一直在寻找

Update: @Alex is correct. The professor was looking for

0110 1100 0111 (1735)

谢谢大家。

推荐答案

您做到这一点,不论以同样的方式,其中数量较大和较小。

You do it the same way irrespective of which number is bigger and which is smaller.

 bb b      bb   <- borrows
 0101 0111 1101 (1405)
-1110 1011 0110 (3766)
 --------------
 0110 1100 0111 (1735?)

现在,如果你想有一个适当的差异,需要考虑溢出,因为上面的结果不包括符号位:

Now, if you want a proper difference, you need to take into account the overflow since the above result doesn't include the sign bit:

 b bb b      bb   <- borrows
 0 0101 0111 1101 (1405)
-0 1110 1011 0110 (3766)
 ----------------
 1 0110 1100 0111 (-2361 signed 2's complement)

说真的,CPU不关心会从什么扣除。它使用整数加​​法/减法相同的算法,而且,此算法是对符号和无符号的整数相同。你只需要正确间preT结果和进位和溢出标志。这就是全部。

Really, the CPU doesn't care what gets subtracted from what. It uses the same algorithm for integer addition/subtraction, moreover, this algorithm is the same for signed and unsigned integers. You only have to correctly interpret the result and the carry and overflow flags. That's all.

这篇关于从一个较小的一个减去一个大的无符号二进制数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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