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

查看:46
本文介绍了如何在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天全站免登陆