如何在ARM中进行除法? [英] How to do division in ARM?

查看:542
本文介绍了如何在ARM中进行除法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于没有DIV命令,因此我试图找到如何在ARM中进行除法的方法.如果可以通过将浮点数[/9 = *0.09]乘以,通过减法或使用库来完成.任何方式都可以.

I m trying to find how to make a division in ARM since there is no DIV command. If that can be done by multiplication of a float number [/9 = *0.09], by subtraction or by the use of a library. Any way would do.

目前,我正在使用像这样的循环使用减法进行除法,但是我舍弃了小数:

Currently I am doing division using subtraction using a loop like this but I loose the decimals:

MOV R0,#70 ;Fahrenheit Temperature
SUB R1,R0,#32 ; Subtracting 32
MOV R4,#0 ;Counter

LOOP 

   ADD R4,R4,#1; Counter+1 ->Is the answer of the division without decimals
   SUB R1,#9
   CMP R1,#0
   BPL LOOP
   MOV R1,R4

所以基本上我在做什么,我的温度是70,我减去32,我得到38.然后在循环中,每次我取9直到提醒小于9.使用正态除法的答案是4.22222.在这里我得到5.所以我的结果不太准确.

So basically what I am doing is that I have temperature 70, I subtract 32 and I get 38. Then in the loop I take 9 each time till the reminder is smaller than 9. The answer using normal division is 4.22222. Here I get 5. So my result is not as accurate.

推荐答案

如果您只想将r0中的整数值除以9,则可以使用以下方法进行近似:

If you just want to divide an integer value in r0 by 9 you can approximate that with:

ldr r3,=0x1C71C71D   # 1C71C71D == (2^32 / 9) + 1
umull   r9,r3,r0,r3

r3现在包含商的整数部分,而r9包含按2 ^ 32缩放的小数部分.要获得余数,只需将商的整数部分乘以9,然后从原始值中减去结果.

r3 now contains the integer part of the quotient, and r9 contains the fractional part scaled by 2^32. To get the remainder you'd just multiply the integer part of the quotient by 9 and subtract the result from the original value.

这篇关于如何在ARM中进行除法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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