-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Diwil!

diwil schrieb:
|>My assumption is, that the calculation should have
|>been (written in C for better understanding):
|
|
|>u16Result = u8Value * 256 - u8Value * 16;
|
|
| Ok... there is a reason:
|
| (uint8_t) cannot be more than 255. Otherwise, the value is truncated to 8
| bits. Therefore u8Value * 256 is always zero.
| To get desired result you have to write       
|       
|       u16 = (unsigned int) u8 * anyting;
|
| Hope this helps.
| ~d

Yes, that was my first assumption, but it is not true.
Even a version with 5 casts to unsigned int doesn't work
and generates all the time the same code.

First try to fix was

u16Result = MACRO * (unsigned int)u8Value;

After that I tryed
(uint16 is a typedef for unsigned short int)

u16Result = (uint16)(((uint16)(MACRO)) * ((uint16)(u8Value)));

and third and final

u16Result = = (uint16)(((uint16)((uint16)MACRO))  *
~                       ((uint16)((uint16)u8Value)));

A little bit extreme and last desperate try to get to the
correct result... nothing worked

And by the way... the value MACRO is defined as 240U
which is already a cast to unsigned int


As far as I know, the C standard defines the following points:

1. Every calculation is done in int and never in unsigned
~   char

2. A calculation is implictly cast to the biggest value
~   type used in the calculation

Any other compiler (inclusive gcc itself) does the
calculation in a proper way. This is a point only
for the mspgcc.

I think, there is only one line in the generated code
missing. This is an add.b of the u8Value to the high
byte of U16Result. Then everything is fine.


Best regards


        Robert Dominicus-Schleutermann

- --
Robert Dominicus-Schleutermann      Telefon : +49 36203 96314
Software+Systeme Erfurt GmbH        Telefon : +49 36203 96301
Fichtenweg 8                        Fax     : +49 36203 96333
D-99198 Erfurt-Kerspleben
eMail: mailto:[email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFC7xsD7kPn7znKZuYRAqiOAJ4uVhPO+cQrVq8jj91Dh7akBTZ44gCfZCaK
5ob3rKwp819YsICGBSnMuwc=
=qRKe
-----END PGP SIGNATURE-----

Reply via email to