有什么方法可以将64位整数除以10的RARS?
我一直在尝试将两个32位登记册除以10。 我知道如果股息为32位,我知道如何分配寄存器,但是如果它是64位。
我无法解决
div s8, s0, a6 # divide a result by 10 (for example, 1234->123)
mul s6, s8, a6 # multiply s8 by 10 (for example, 123->1230)
sub s7, s0, s6 # the result - s6 (for example, 1234-1230->4)
beqz s7, output # if s7 is zero, jump
。
该部门更棘手。您可以通过comapare,移位和减法实现常规二进制划分,也可以使用另一种方法:考虑到A * 2^32 + b,请考虑64位号AB(A和BE为32位数字)。表示2 ^32为x * 10 + y。然后ab / 10 = x +(y *a + b) / 10。如果您两次使用此方法,则可以将64位的划分降低10至32位。< / p>
但是我不明白,如果我两次使用此方法,为什么我可以获得32位号。
I have been trying to divide two 32-bit registers by 10.
I know how to divide a register if a dividend is 32-bit like the following code, but I cannot solve if it's 64-bit.
div s8, s0, a6 # divide a result by 10 (for example, 1234->123)
mul s6, s8, a6 # multiply s8 by 10 (for example, 123->1230)
sub s7, s0, s6 # the result - s6 (for example, 1234-1230->4)
beqz s7, output # if s7 is zero, jump
And I found a tips that
The division is more tricky. You may either implement regular binary division by comapare, shift and subtract or use another method: Think of a 64bit number ab (where a and be are 32-bit numbers) as of a * 2^32 + b. Express 2 ^32 as x * 10 + y. Then ab / 10 = x + (y *a + b) / 10. If you apply this method twice, you may reduce 64-bit division by 10 to a 32-bit one.
But I cannot understand why I can get a 32-bit number if I apply this method twice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论