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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

ソリューションへジャンプ
1,138件の閲覧回数
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 解決策
731件の閲覧回数
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 返答(返信)
732件の閲覧回数
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 件の賞賛
返信
731件の閲覧回数
CASEYKEVIN
Contributor I

follow you advices,  i get the correct result

 

thanks very much

0 件の賞賛
返信