Arduino inline assembly: 16 bit x 8 bit multiplication!

westfw:
In this case, since the AVR has neither a 16byte shift, nor a multibit shift, the best possible implementation using shifts is going to be the same as the implementation using adds. "i+i" is left shift once. "(i+i)+(i+i)" is left shift twice. In fact, on the AVR, the "LSL Rd" (Logical Shift Left) instruction is just an alias for "ADD Rd, Rd"

The nice thing about using a compiler, and the reason that 'large' programs tend to be smaller and faster when written in C rather than ASM, is that this sort of optimization will be applied ALL OVER the program, and not just in the places where you remember to optimize by hand. (actually, the nice part about using the compiler is that you don't have to figure out how to do an 8x16 multiply given an 8x8 multiply instruction (or nothing) in the first place!)

Thanks for the valuable info... :smiley: