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
Hi Jon, this is my Assembler-Code:
545: void NumToHex(unsigned int Handle) 00010246 ECFD PUSH R13 00010248 F0D8 MOV R13,R8 0001024A 06F0F0FF ADD R0,#0xFFF0 546: { 548: const unsigned char numbers[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; 0001024E F060 MOV R6,R0 00010250 E6F40040 MOV R4,#0x4000 00010254 E6F71000 MOV R7,#0x0010 00010258 CA00E609 CALLA+ CC_UC,?C_BCPYNN(0x109E6) 550: putchar('0'); 0001025C E6F83000 MOV R8,#0x0030 00010260 BBDF CALLR putchar(0x10220) 551: putchar('x'); 00010262 E6F87800 MOV R8,#0x0078 00010266 BBDC CALLR putchar(0x10220) 563: putchar(numbers[(Handle>>12) & 0x0f]); 00010268 F04D MOV R4,R13 0001026A 7CC4 SHR R4,#0x0C 0001026C 66F40F00 AND R4,#0x000F 00010270 F010 MOV R1,R0 00010272 0014 ADD R1,R4 00010274 A981 MOVB RL4,[R1] 00010276 C088 MOVBZ R8,RL4 00010278 BBD3 CALLR putchar(0x10220) 564: putchar(numbers[(Handle>>8) & 0x0f]); 0001027A F04D MOV R4,R13 0001027C 7C84 SHR R4,#0x08 0001027E 66F40F00 AND R4,#0x000F 00010282 F010 MOV R1,R0 00010284 0014 ADD R1,R4 00010286 A981 MOVB RL4,[R1] 00010288 C088 MOVBZ R8,RL4 0001028A BBCA CALLR putchar(0x10220) 565: putchar(numbers[(Handle>>4) & 0x0f]); 0001028C F04D MOV R4,R13 0001028E 7C44 SHR R4,#0x04 00010290 66F40F00 AND R4,#0x000F 00010294 F010 MOV R1,R0 00010296 0014 ADD R1,R4 00010298 A981 MOVB RL4,[R1] 0001029A C088 MOVBZ R8,RL4 0001029C BBC1 CALLR putchar(0x10220) 566: putchar(numbers[Handle & 0x0f]); 567: 568: //and goto next line 0001029E F04D MOV R4,R13 000102A0 66F40F00 AND R4,#0x000F 000102A4 F010 MOV R1,R0 000102A6 0014 ADD R1,R4 000102A8 A981 MOVB RL4,[R1] 000102AA C088 MOVBZ R8,RL4 000102AC BBB9 CALLR putchar(0x10220) 569: putchar(10); 000102AE E0A8 MOV R8,#0x0A 000102B0 BBB7 CALLR putchar(0x10220) 570: putchar(13); 000102B2 E0D8 MOV R8,#0x0D 000102B4 BBB5 CALLR putchar(0x10220) 571: }