'错误'在ARM减指令进位标志的使用情况如何? [英] 'Wrong' usage of carry flag in ARM subtract instructions?

查看:134
本文介绍了'错误'在ARM减指令进位标志的使用情况如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与携带ARM减法指令( SBC RSC )间preT进位标志(C )为:


  • 0手段借

  • 1表示没有借

为什么进位标志 C 反转为使算术?

  SBC R0,R1,R2 @ R0 = R1  -  R2  - !ç


解决方案

我们从小学知道

  A = B  -  C = B +(-c)

和从否定一些二进制补码,我们颠倒电话号码,并添加一个如此基本的编程类

  A = B +(〜C)+ 1

和完美地工作,因为当我们养活加法逻辑我们的价值观,我们反转第二个操作数和反转的随身携带。(有你用加法做减法没有减法逻辑)

因此​​,一些处理器实现选择反转开展。您已经反转的东西做减法,并将原始开展正常的减法(没有借位)的最高位是1的时候,有借的开展是0,所以反转开展然后你可以称之为借用,而不是进位(或代替/或借!借用或borrow_n)

而且,任何方式,你做到这一点,如果你有借减法,那么你需要或者反转或不反转进位取决于您的设计选择对减法(正常不借)的开展。

所以减法

  A = B +(〜C)+ 1

当你级联减法(SBC),那么如果没有借那么

  A = B +(〜C)+ 1

但是,如果有借那么下一个级别需要有一个1去除,以使SBC成为

  A = B +(〜C)

在进位是在这种情况下,一个零。因此,从加法逻辑的角度来看,当你做一个减法借你自然有反转第二个操作数,但您在0随身携带,如果你不得不借,并在1随身携带,如果你没有。

在SBC臂文档说


  

路=路 - 罗 - NOT(C标志)


所以,如果我们需要一个客场由于之前借那么C需要的是一个0,否则,C是1将在

在减法基本上都是说


  

C标志= NOT BorrowFrom(操作)


因此​​,如果我们需要借用然后借用所以C标志是不正确的或0。如果我们不需要借钱,然后从为假0借钱,而不是从借钱是1。所以这一切都是真实的相匹配,如果我们需要借钱,然后进入SBC C需用为0。

所以基本上ARM不会出现修改从加法器的开展。因此它不需要反转进位在上一个SBC

The ARM subtraction instructions with carry (SBC, RSC) interpret the carry flag (C) as:

  • 0 means borrow
  • 1 means no borrow

Why carry flag C is inversed to make the arithmetic?

SBC R0, R1, R2 @ R0 = R1 - R2 - !C

解决方案

We know from grade school that

a = b - c = b + (-c)

and from elementary programming classes that to negate a number in twos complement we invert a number and add one so

a = b + (~c) + 1

And that works out perfectly because when we feed the adder logic our values we invert the second operand and invert the carry in. (there is no subtract logic you use an adder to do subtraction)

So some processor implementations choose to invert the carry out. You are already inverting stuff to do a subtract, and the raw carry out of the msbit on a normal subtract (without borrow) is a 1, when there is a borrow the carry out is a 0, so inverting the carry out you can then call it a "borrow" instead of a carry (or instead of a /borrow or !borrow or borrow_n)

Which ever way you do it, if you have a subtract with borrow, then you need to either invert or not invert the carry in depending your design choices for the carry out on a subtract (normal without borrow).

So subtraction is

a = b + (~c) + 1

And when you cascade that subtraction (sbc) then if there was no borrow then

a = b + (~c) + 1

But if there was a borrow then that next level needs to have a 1 removed so the sbc becomes

a = b + (~c) 

The carry in is a zero in that case. So from the adder logic perspective when you do a subtract with borrow you naturally have to invert the second operand, but you carry in a 0 if you have to borrow and carry in a 1 if you dont.

The arm docs on a SBC say

Rd = Rd - Rm - NOT(C Flag)

So if we need to take one away due to a prior borrow then C needed to be a 0 else C is a 1 going in.

The subtractions all basically say

C Flag = NOT BorrowFrom(operation)

So if we need to borrow then borrow from is true so C flag is not true or a 0. If we dont need to borrow, then borrow from is false a 0, and not borrow from is a 1. So that all matches up, if we needed to borrow then going into SBC C needs to be 0.

So basically ARM does not appear to modify the carry out from the adder. And so it does not need to invert the carry in on an SBC.

这篇关于'错误'在ARM减指令进位标志的使用情况如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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