This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

16X16, 16X8 bit software multiplication

Other Parts Discussed in Thread: MSP430F2618

Hi

I am using MSP430f2618 and IAR compiler.

I would like to implement the follwing multiplication in software rather than using the hardware mulitiplier.

I am trying to multiply a 16 bit number with an 8 bit number and the result is going to be more than 16 bits. If i directly multiply them then my Most significant bits are chopped off and the least significant 16 are available. can I know How I can get the 16 bit results where I can retrive the most significant 16 bits. see the following example

typedef unsigned short  WORD;

typedef unsigned char BYTE;

WORD i, result;

BYTE j;

void main( )

{

i = FECA; // 16 bit number

J = FF;  // 8 bit number

result = I*J; // my result = CB36 (16 bits with most significant bits chopped off)

// the Ideal result should be FDCB36 and my desired result is FDCB (16 most significant bits)

}

Thank you;

 

 

}

 

 

 

 

 

 

  •  

    Hi

     

    You must declare the result variable as long int (32 bits). Then you must type-cast the multiplication operation for (long int).

    The mul16 assembly implementation use registers R12 and R13 to return the result.

     

    See the example bellow.

    ----------------------------------------------

    typedef unsigned short  WORD;

     

    typedef unsigned char BYTE;

     

    WORD i;

     

    BYTE j;

     

    long unsigned int result;

     

    void main( )

     

    {

     

    i = 0xFECA; // 16 bit number

     

    j = 0xFF;  // 8 bit number

     

    result = (long int) i*j; // my result = CB36 (16 bits with most significant bits chopped off)

     

    // the Ideal result should be FDCB36 and my desired result is FDCB (16 most significant bits)

     

    }

    ----------------------------------------------

     

    Best Regards,

    AES

     

**Attention** This is a public forum