How to do the modulo operation in ARM assembly?

蹲街弑〆低调 提交于 2021-01-29 04:21:49

问题


I'm trying to add the values in two registers, and modulo them by 8. So, in C code, it would be like this

a = a + b;
c = a % 8;

how to do this above operation in ARM assembly.


回答1:


Not all ARM processors have a direct instruction for division or modulo, so in most cases, a call to the modulo operation would end up as a function call to e.g. ___modsi3.

In this particular case, when doing modulo for 8, if the values can be assumed to be nonnegative, you can do the % 8 part as & 7. In that case, the assembly for your case would be:

add rA, rA, rB
and rC, rA, #7


来源:https://stackoverflow.com/questions/42938673/how-to-do-the-modulo-operation-in-arm-assembly

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