Hello Forum, I want to compose two int variables, which contains the LSW and MSW, respective, into one unsigned long variable. The following code does the right thing:
int lo, hi; unsigned long longvar; longvar = (unsigned long) (unsigned int) hi << 16 | (unsigned long) (unsigned int) lo;
longvar.msw = hi; longvar.lsw = lo;
The Keil C compiler is not the smartest in the world when it comes to optimization. In some situations it will never match the performance of direct assembler coding, whatever ways of doing the same thing in C you try.