Unsigned 16b multiply question:
When doing unsigned 16bit multiplys, why is it (apparently)
necessary to perform casts to 32b unsigned first?
Using v3.2.3 from ~ 4weeks ago (linux) on MSP430x149
For Example:
int main(void)
{
unsigned int a= 0xFFFF ;
unsigned int b= 0xFFFF ;
unsigned long c ;
unsigned long d ;
c = a * b;
d = (unsigned long)a * (unsigned long)b ;
return(0);
}
/* Resulting List
<main>:
31 40 00 0a mov #2560, r1 ;#0x0a00
3f 43 mov #-1, r15 ;r3 As==11
02 12 push r2 ;
32 c2 dint
03 43 nop
82 4f 32 01 mov r15, &0x0132 ;<** Signed ???
82 4f 38 01 mov r15, &0x0138 ;
1e 42 3a 01 mov &0x013a,r14 ;0x013a
32 41 pop r2 ;
02 12 push r2 ;
32 c2 dint
03 43 nop
82 4f 30 01 mov r15, &0x0130 ;
82 4f 38 01 mov r15, &0x0138 ;
1e 42 3a 01 mov &0x013a,r14 ;0x013a
1f 42 3c 01 mov &0x013c,r15 ;0x013c
32 41 pop r2 ;
0f 43 clr r15 ;
30 40 78 11 br #0x1178 ;
*/
- Bill Hall