简体   繁体   中英

ARM assembly, multiplying without MUL instruction

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.

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>

and a terrible joke: Use the Tools, Luke!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM