进位标志减法 [英] Carry flag in substraction

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

问题描述

我使用MASM32。

有了这个code:

  MOV EAX,5
子EAX,10

CF状态标志将被设置。但是,用我的笔和纸,我居然看到有从MSB没有任何矣。是的,我知道,从减法从少一些大量设置CF.但我想知道为什么吗?

由于使用此code:

  MOV EAX,5
MOV EBX,10
不EBX
加EBX,1
添加EAX,EBX

CF标志不会被永远设置。


解决方案

  5  -  10 = 5 +(-10)= 0×05 +(0xF5 + 1)= 0×05 + 0xF6 = 0xFB的才能  00000101  -  0×05
  11110101 - 0xF5
+ 00000001 - 0×01
==========
  11111011 - 0xFB的才能

和这个持续16或32或64位0 + 1 + 0 = 1,携带0

你是对的,即它不执行。减法是一个倒置的第二个操作数和反向套利补充。一些处理器家族反转进行一些不。听起来你正在寻找的东西,反转开展减法。

所以,如果5 - 10给出了执行(借),然后尝试。10 - 5在同一处理器上,你不应该看到进位设置(无借)

您第二个例子是一个附加的操作,进行不倒的,我知道的任何处理器,进一步支持了进位为正逻辑表示借。

I am using MASM32.

With this code:

mov eax,5
sub eax,10

CF status flag will be set. But using my pencil and paper, I actually see that there is no any carry from MSB. Yes, I know that from subtraction from less number great number set CF. But I want to know why?

Because using this code:

mov eax,5
mov ebx,10
not ebx
add ebx,1
add eax,ebx

CF flag won't be ever set.

解决方案

5 - 10 = 5 + (-10) = 0x05 + (0xF5 + 1) = 0x05 + 0xF6 = 0xFB

  00000101 -- 0x05
  11110101 -- 0xF5
+ 00000001 -- 0x01
==========
  11111011 -- 0xFB

And this continues for 16 or 32 or 64 bits 0+1+0 = 1, carry 0

You are right in the sense that it doesnt carry out. A subtract is an add with the second operand inverted and the carry in inverted. Some processor families invert the carry out some dont. Sounds like you are looking at something that inverts the carry out on a subtract.

So if 5 - 10 gives carry out (borrow) then try 10 - 5 on the same processor, you should not see the carry bit set (no borrow).

Your second example is an add operation, the carry out is not inverted on any processor that I know of, further supporting the carry bit being positive logic indicating a borrow.

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

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