This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Q: Compiler generates wrong Assembler Code

I am involved within the development of some control hardware using the Infeneon XC161 processor with a "self made" evaluation board.
I think something is wrong with the compiler.
First I thought that there is a bug on the board, but most program parts are running.
Measurments on the board end up in the result that everything works fine.

I used the internal debuger to check out what asm code really has been generated.
I was upset! Some Variables are lost after a function reentry. My code works fine with constants, but if I put some evalation expressions between the lines everything goes wrong.

Here is the Code example:

This short code should write integer numbers thoug the serial port. "putchar( uint )" works!

void NumToHex(unsigned int Handle)
{
const unsigned char numbers[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

//write the number into RS232
putchar('0');
putchar('x');
putchar( (unsigned char) numbers[ ((Handle & 0xf000) >> 12) ] );
putchar( (unsigned char) numbers[ ((Handle & 0x0f00) >> 8) ] );
putchar( (unsigned char) numbers[ ((Handle & 0x00f0) >> 4) ] );
putchar( (unsigned char) numbers[ (Handle & 0x000f) ] );

//and goto next line
putchar(10);
putchar(13);
}

*****
this code always returns "0x ". But there should be something like "0x0a25".

If I try

putchar( (unsigned char) numbers[0] );
putchar( (unsigned char) numbers[13] );
putchar( (unsigned char) numbers[2] );
putchar( (unsigned char) numbers[1] );

everything works fine.
I checked the range of my shifting-results.
All Numbers stay between 0 and 15.

PLEASE HELP ME. I nearly go mad with this.
Is there anything wrong with the compiler?
Have I forgotten a bracket?
Could there be a problem with my memory-configuration?

thanks for your answers

Jacek Wisniowski

0