64 bit division in ARM Assembly SOS

此生再无相见时 提交于 2019-12-06 13:05:24

Given that there's a 64 bit signed integer in r0 and r1, one can divide it by 16 with the following instructions:

    lsl     r2, r0, #28
    asr     r0, r0, #4
    orr     r1, r2, r1, lsr #4

In a nutshell, all we need to do is to shift both halves by four and put lower four bits of r0 into four upper bits of r1.

To get unsigned division, one should use lsr instead of asr.

In both cases the result will be rounded towards minus infinity. To round the result towards the nearest integer one can add 8 to the integer before division. Also, one can add 15 to round towards plus infinity.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!