Could someone point me out how to modify it so that the second argument isn't
hardcoded or just take power of 2 from the input.
uint16_t mul(uint16_t input1, uint16_t input2){}
On 03.09.2010, at 2:31, William Chops Westfield wrote:
>
> On Sep 2, 2010, at 12:35 PM, Andres Vahter wrote:
>
>> mov.w R12,R13 ; The operand "input" in
>> register R12
>> rla.w R13
>> add.w R12,R13 ; X1=X*2^1+X
>> rla.w R13
>> rla.w R13
>> add.w R12,R13 ; X2=X1*2^2+X
>> rla.w R13
>> add.w R12,R13 ; X3=X2*2^1+X
>> rla.w R13
>> add.w R12,R13 ; X4=X4*2^1+X
>> rla.w R13
>> rla.w R13
>> rla.w R13
>> add.w R12,R13 ; Final Result=X5=X4*2^3+X
>
> It computes (((X*2 + X)*4 + X)*2 + X)*2 + X)*8 + X
> = (12X) + X)*2 + X)*2 + X)*8 + X
> = 26X + X)*2 + X)*8 + X
> = 54X + X)*8 + X
> = 440X + X
> = 441*X
>
> Which is what it said at the top; multiplies 41 * 441.
> It looks to me like a pretty standard multiplication algorithm, only
> since one argument is a know constant, you get to leave out the steps
> that would involve adding 0.
>
> I've seen code generators for other microcontrollers that claim to
> generate the optimal sequence for multiplying a register by any
> constant. It should be possible to do for MSP430 too. Perhaps the C
> compiler already does so? (probably not; I've also seen complaints
> that gcc does a poor job of multiplying by constants.)
>
> BillW
>
>
> ------------------------------------------------------------------------------
> This SF.net Dev2Dev email is sponsored by:
>
> Show off your parallel programming skills.
> Enter the Intel(R) Threading Challenge 2010.
> http://p.sf.net/sfu/intel-thread-sfd
> _______________________________________________
> Mspgcc-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users