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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
1,613 次查看
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

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,206 次查看
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 项奖励
回复
2 回复数
1,207 次查看
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 项奖励
回复
1,206 次查看
CASEYKEVIN
Contributor I

follow you advices,  i get the correct result

 

thanks very much

0 项奖励
回复