ARM 汇编,无需 MUL 指令的乘法 [英] ARM assembly, multiplying without MUL instruction

查看:31
本文介绍了ARM 汇编,无需 MUL 指令的乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此进行了广泛的研究,但没有找到任何答案.我需要在不使用 ARM 汇编语言中的乘法指令的情况下乘以 a*17.我知道您可以使用 RSB,但是如何设置值或使用 LSL# 部分让我感到困惑.任何帮助都会很棒!!

I have researched this extensively, and have not found any answers. I need to multiply a*17 without using the multiply instructions in ARM assembly language. I understand you can use RSB, but how to set up the values or use the LSL# part is confusing to me. Any help would be great!!

推荐答案

我同意评论但只是一个快速提示,编译器通常非常擅长通过常量优化乘法.

I agree with comments but just a quick tip, compilers are generally really good at optimizing multiplications by constants.

因此您可以使用 arm-*-*-gcc 工具链来获得此类答案.

So you can just use an arm-*-*-gcc toolchain to get this kind of answers.

$ cat m17.c 
int f(int i) {
    return i * 17;
}

$ arm-linux-gnueabihf-gcc -O3 -S m17.c
$ cat m17.s
        <skipped>
f:
    add r0, r0, r0, lsl #4
    bx  lr
    <skipped>

还有一个可怕的笑话:使用工具,卢克!

这篇关于ARM 汇编,无需 MUL 指令的乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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