CodeWarriro don`t support 16-bit multiply 16-bit

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CodeWarriro don`t support 16-bit multiply 16-bit

Jump to solution
1,056 Views
CASEYKEVIN
Contributor I

in my application, i  need  operation of 16-bit * 16-bit

 

volatile  dword  mytempDword;

volatile  word   mytempword1 = 300;

volatile  word   mytempword2= 312;

 

main()

{

   ...

 

 mytempDword =  mytempword1 * mytempword2;

 

}

 

Codewarriror gives wrong result of  28064, but the correct result is 93600,  i found that 93600 = 65536 + 28064 , obviously, the 16th bit is  ignored by CodeWarrior.  why?   my setting options of CodeWarrior is default. and CodeWarriror version is 5.9

 

Anybody here know why? thanks

 

regards

Labels (1)
Tags (1)
0 Kudos
1 Solution
649 Views
rocco
Senior Contributor II

Hi CaseyKevin,

 

A word can hold an unsigned number from 0 to 65535, or a signed number from -32768 to +32767.

 

The number 93600 would require at least 17 bits.

 

If you cast the words into dwords before you multiply, you should get the correct result.

View solution in original post

0 Kudos
2 Replies
650 Views
rocco
Senior Contributor II

Hi CaseyKevin,

 

A word can hold an unsigned number from 0 to 65535, or a signed number from -32768 to +32767.

 

The number 93600 would require at least 17 bits.

 

If you cast the words into dwords before you multiply, you should get the correct result.

0 Kudos
649 Views
CASEYKEVIN
Contributor I

follow you advices,  i get the correct result

 

thanks very much

0 Kudos