user2860551
user2860551

Reputation: 13

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!!

Upvotes: 1

Views: 5395

Answers (1)

auselen
auselen

Reputation: 28087

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!

Upvotes: 1

Related Questions