This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C-Disassembly translation to assembly confusion

Hi all. 

I have working C code that I am trying to make more efficient for maximum speed.

I want to translate to asm code and then go through each command to optimize where I can.  I have done this before successfully for other code snippets.

This time, however, I am running into an issue where the asm code that I have copied from the disassembly is not functioning in the same manner as the C code.  Even though I copied the disassembly line from line.  I've done it twice now to ensure there aren't any copy and paste errors.

The error is occurring at the end of a for loop.  Here is the disassembly of that section:
109         for (i; i <= 23; i++)
        C$L17:
3f61c7:   0A41        INC          *-SP[1]
3f61c8:   9241        MOV          AL, *-SP[1]
3f61c9:   5217        CMPB         AL, #0x17
3f61ca:   56C5FE94    BF           -364, LEQ

This occurs at the end of the code of the for loop, just after i is incremented, and compared to repeat the loop or not.  The highlighted line is what is causing me grief.  In C this line will execute without error.  copying this from disassembly to asm code and executing the line drops me out of the function and I get:
"No source available for "0x3f5fff" and dropped into interrupt void ILLEGAL_ISR(void) with an ESTOP0 and infinite for loop.

So my question is what could cause this difference?  Is there something else happening in the disassembly behind the scenes that I'm not seeing?
As I said earlier, I have used this method of copying disassembly into an asm source file several times now and Ive never come across one line that is executing differently.

The whole code chunk is quite long.  I will post it later if needed.

Thanks in advance.

  • There's a bit of a disconnect between the disassembly and the input the assembler expects. The TI ARM disassembler does not guarantee that its output is valid input to the assembler. You should instead keep the assembly code generated by the compiler using the --keep_asm option, and modify that.

    You need to feed BF a label or a label expression, but the disassembler is giving you a PC-relative offset, which is actually what gets encoded. You can try '$-364', but I'm not sure that's exactly right. You probably need to add a label to the assembly code where the branch destination should be and branch to that label.
  • Awesome. Thanks.

    Can you go into some more detail regarding the --keep_asm option please?

    I found the check option in preferences. Is there anything else that is needed, or is checking it sufficient. Where is the assembly file saved to?

    (No the $-364 didn't work. But I appreciate the shot in the dark :) )
  • The assembly file is usually placed in the temporary objects directory, the same place you'll find the object files.  

    See the compiler manual at http://processors.wiki.ti.com/index.php/TI_Compiler_Information#Compiler_Manuals

    See C28x compiler user's guide section "2.3.10 Specifying Directories" and ... well, that's curious, section 2.3.11 is supposed to document --keep_asm

  • Perfect. I found the main.asm and function.asm that I needed in the project debug folder.

    the line in the assembly generated was:
    BF C$L1, LEQ

    as in go to C$L1, which was the start of the for loop in quesiton.

    Curiously, the actual generated code had $C$L1 as the actual destination. I had to remove the '$' for the code to compile. The disassembly doesn't have any dollar signs, whereas the generated assembly has all dollar signs.
  • The disappearing dollar sign is a quirk of the CCS disassembly, and the fact that $ is used in COFF mode to prefix thumb functions. The actual symbol in the object file had the dollar prefix. It's not required, just convention for compiler-generated labels.