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

Parents
  • Maybe there is another problem? How are you testing the code?
    I use de Debugger and upload to my hardware-device.
    Have you used the correct startup code for the XC devices?
    I think so. Most components work, just this one is not working.
    Where is the user stack located? Is that memory area valid?
    Yes. There was a problem with the user stack in a previous code-version. A bigger User stck solved problems with procedure calls. But a bigger Stack Size results in "out of memory" behaviour.
    Do you get any compiler warnings or linker warnings?
    No, no errors and warnings.

    I think that anything is different between the debugger settings and my device settings. But I dont't know where to look for.

    I've had problems with calling procedures. we made some changes in the memory setup and after that the calls worked. I will try to call the HexNum()-code in main(). If this is working it might be the startup-code (stack).

    Do you know any problems with startup-code, memory setup and function-calls?

    My assembler code looks similar to yours.
    What errors can result from wrong startup-code (I took the default-startup-code for XC161)? I work with the "medium" Memory modell.

    I can show you the assembler code in my next posting after I am at work again, tomorrow.

    Jacek

Reply
  • Maybe there is another problem? How are you testing the code?
    I use de Debugger and upload to my hardware-device.
    Have you used the correct startup code for the XC devices?
    I think so. Most components work, just this one is not working.
    Where is the user stack located? Is that memory area valid?
    Yes. There was a problem with the user stack in a previous code-version. A bigger User stck solved problems with procedure calls. But a bigger Stack Size results in "out of memory" behaviour.
    Do you get any compiler warnings or linker warnings?
    No, no errors and warnings.

    I think that anything is different between the debugger settings and my device settings. But I dont't know where to look for.

    I've had problems with calling procedures. we made some changes in the memory setup and after that the calls worked. I will try to call the HexNum()-code in main(). If this is working it might be the startup-code (stack).

    Do you know any problems with startup-code, memory setup and function-calls?

    My assembler code looks similar to yours.
    What errors can result from wrong startup-code (I took the default-startup-code for XC161)? I work with the "medium" Memory modell.

    I can show you the assembler code in my next posting after I am at work again, tomorrow.

    Jacek

Children
  • My assembler code looks similar to yours.

    Well, mine works so the generated code isn't the problem.

    What errors can result from wrong startup-code (I took the default-startup-code for XC161)?

    Just about any kind of error you could imagine. For example, the chip selects are configured in the startup code. If this is not configured correctly, your program would appear to have no RAM or ROM memory.

    Your problem really sounds like a configuration issue. Have you checked to see that the startup code matches your hardware configuration?

    Jon

  • 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: }
    

    It's not woking with my device.
    I will check stack and memory settings.
    Thank you for your help.

    Jacek