ARM DIVISION如何做呢? [英] ARM DIVISION HOW TO DO IT?
问题描述
我米试图找到如何在ARM分工,因为没有DIV命令。如果可以通过浮法数目的乘法来完成[/ 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] or by the use of a library or by using Subtraction. Any way would do. Thank you in advance.
目前,我司做减法使用,但我失去的小数。
我米这样做,使用循环
Currently I am doing division using subtraction but i loose the decimals. I m doing that using a loop
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.
推荐答案
如果你只是想通过9分在 R0
的整数值可以近似与
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 DIVISION如何做呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!