问题
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