如何在ARM汇编中进行模运算? [英] How to do the modulo operation in ARM assembly?

查看:127
本文介绍了如何在ARM汇编中进行模运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将值添加到两个寄存器中,并以8为模.因此,在C代码中,就像这样

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;

如何在ARM汇编中执行上述操作.

how to do this above operation in ARM assembly.

推荐答案

不是所有的ARM处理器都有直接的除法或模运算指令,因此在大多数情况下,对模运算的调用最终会作为对例如的函数调用而结束. ___ modsi3 .

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.

在这种特殊情况下,对8取模时,如果可以认为这些值是非负的,则可以将%8 部分作为&7 .在这种情况下,适合您的情况的程序集将是:

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

这篇关于如何在ARM汇编中进行模运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆