Arduino inline assembly: 16 bit x 8 bit multiplication!

DirtyBits:
It's much faster to do in assembly.. :smiley:

That is very unlikely to be true. The compiler writers know the processor backwards. As others have pointed out earlier the compiler already optimizes your requirements into six adds and a move. That's only 7 clock cycles. So even looking up "multiplication" in the assembler manual is going to lead you down the path of something that is potentially "much slower".

robtillaart:
I would code x = x* 5 as x = x + x <<2; if I wanted to optimize

Rob's idea is what I would have suggested myself. Bit shift by 2 to multiply by 4, and then add in the last one.

The other problem with assembly is that you will probably generate code to load the variables from memory, into registers. What else could you do? But the compiler may know the variables are already in certain registers and can skip that step.

This thread is starting to sound like a lot of other ones, like "how do I break out of an interrupt?". Let's step back ... WHY do you need to multiply something by 5 "much faster" than can be done in C?