| ??? 05/22/03 02:49 Read: times |
#46327 - RE: 8-bit*16-bit multiplication Responding to: ???'s previous message |
And now if you want to get rid of any pesky library calls (portability is left as an exercise for the reader):
typedef unsigned char U8;
typedef unsigned short U16;
typedef unsigned long U32;
union U32_
{
U32 l;
U16 w[2];
U8 b[4];
};
U32 product;
U32 Mul8x16(U8 b, U16 w)
{
union U32_ retVal;
U16 tmp;
tmp = b * (U8)w;
retVal.l = b * (U8)(w >> 8);
retVal.b[1] = retVal.b[2];
retVal.b[2] = retVal.b[3];
retVal.b[3] = 0;
return (retVal.l + tmp);
}
void main(void)
{
product = Mul8x16(0x80, 0x1234);
}
|



