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 file and asm file in the same project

Other Parts Discussed in Thread: TMS320C6455

Hello,

I am writing a small program and small subroutine. My main progam is in C language and subroutine is in asm language. both c and asm are in two different files.

I have included both the file in the same project and completed the build successfully.

when I keep breakpoint in asm file, the break point is not getting hit and the program is hung.

the file names are main.c and dotp.asm

environment : CCS5.5, TMS320C6455 simulator mode.

Here are my questions :

1. Do I need to do any special setting when I include asm file into the project

2. how the c program knows that the subroutine is in asm file ?

3. Any other setting I need to do in the project ?

quick help in this regard is highly appreciated.

Thanks and Regards,
Divakar

  • Hi Divakar,
    You should be able to debug the asm code too.
    Can you put just nop in asm file and check whether able to debug ?

    By the way, able to execute the code in free run without any hang ?
  • Hi Shankari,

    You didn't answer to my specific questions in my above post.

    To clarify further, debugger is not hitting asm file. I am doubting whether asm file got linked properly or not.

    I wanted to know what is the procedure to link both c and asm file in the same project.

    Please provide proper steps.

    Thanks and Regards,

    Divakar

  • Divakar,

    You asked your question in the hardware-oriented C64x Single Core DSP Forum. We will ask a Moderator to move this to the Compiler forum where it will be addressed differently.

    Here, we use assembly and C all the time and it works fine. We follow the guidelines in the C/C++ Compiler User's Guide section titled "Interfacing C and C++ With Assembly Language". If you are following the steps there, you should be working fine. Please reply back with the confirmation of that, so the compiler team will be able to help you better.

    We might have been able to help a little with answers to Shankari's questions. Those steps are the path we take to try to understand your situation. His methods of using NOP and testing without breakpoints are valid and normal for our purposes - I repeat these same steps many times because things do not always work the first time.

    Best regards,
    RandyP
  • Divakar Kasamsetty said:
    I wanted to know what is the procedure to link both c and asm file in the same project.

    I presume you build with Code Composer Studio (CCS). From the perspective of CCS, there is no difference between a C source file and and an assembly source file. They are both built by invoking the compiler shell program cl6x. In both cases an object file is generated. And each resulting object file is supplied to the linker to create the final executable file.

    Note the compiler shell cl6x does handle the files differently. It uses the file extension (.c or .asm) to know how to build the file. C source is built differently from assembly source. The resulting object file is treated the same whether it started as C or assembly.

    Thanks and regards,

    -George

  • Sorry I overlooked the following in my last response ...

    Divakar Kasamsetty said:
    Please provide proper steps.

    I presume you know how to build a project where all the source files are C.  If not, then please see this wiki article.  I'm worried it is a bit too much for your situation.  This article is a comprehensive review of all the features in CCS related to organizing and building a project.  

    Once you have that working, add one more file that contains your assembly source.  Make sure the file extension is .asm.  That's all there is to it.

    Thanks and regards,

    -George

  • Hi George/RandyP,
    Thank you for your response.
    Hi George,
    Coming back to specific questions from your side, Let me explain below :
    Environment : CCS 5.5 and TMS320C6455 Simulator
    1. First I wrote only C program which does dot product, entire code was written in C
    2. I was able to build the project successfully by adding C file and configuration file
    3. I could debug it and step through the C code till the end and verified the result.
    With the above steps, it confirms the environment is proper
    4. Now I removed C subroutine from the code and added assembly subroutine in a separate file
    5. I included new asm file to the project and built it successfully.
    6. Now, I am not able to step through the entire code completely, as soon C subroutine call is getting hit, the project is getting hung and I need to kill the debug project.

    Do let me know if I am missing any step here.
    Thanks and Regards,
    Divakar
  • Divakar Kasamsetty said:
    4. Now I removed C subroutine from the code and added assembly subroutine in a separate file

    Please attach two files to your next post.  This assembly file, and the C file which calls the function defined in the assembly file.  Add the file extension ".txt", otherwise the forum rejects it.

    Thanks and regards,

    -George

  • Hi George,

    I am having difficulty in uploading the files. Please find below the snapshot for your reference. Let me know your findings.

    main.c

    /* Prototype */
    int dotp(short *m, short *n, int count);

    /* Include Files */            
    #include "data.h" 

    /* Definitions */
    #define COUNT 256

    /* Declarations */
    short a[COUNT] = {A_ARRAY};
    short x[COUNT] = {X_ARRAY};
    int y = 0;    

    /* Main Code */
    main()
    {
     y = dotp(a, x, COUNT);
    }

    dotasm.asm

    *
    * Dotp assembly subroutine
    *
     .global _dotp
     
    ****************************************************** 
    *
    * Register definitions
    * A0 = a value
    * A1 = x value
    * A2 = counter
    * A3 = product
    * A4 = address of a and Y to be returned
    * A6 = original counter value
    * B0 = working Y value
    * B4 = address of x
    *****************************************************
      .sect ".text"  ; What section is this put into
           ;   so the linker can find it  
    dotp .asmfunc 
    _dotp: 
     
      zero B0    ; initilize y=0
      mv  A6, A2   ; set up counter
    loop ldh  *A4++, A0  ; put the value of a into A0
      ldh  *B4++, A1  ; put the value of x into A1
      nop  4
      mpy  A0, A1, A3  ; a * x --> product
      nop       ; put counter into A2
      add  A3, B0, B0  ; product + previous Y = Y
      sub  A2,1,A2
     [A2] b  loop   ; repeat loop counter times
      nop  5
      
      mv  B0, A4   ; store return value
      
      b  B3    ; return to main
      nop  5 
      .endasmfunc

  • Divakar,

    I do not see anything wrong in your code here, so while you wait for the real expert to return in the morning (USA), I will make a couple of comments.

    To insert a file, click the "Use rich formatting" link in the bottom right corner of the reply/edit box. This will bring up a new editor view and will include a ribbon of editing tools. One of them is for inserting a file. Be sure to do like George suggested and append .txt to your file names.

    In the debugger, I will assume that it loads the program correctly and puts the PC at main. Is that correct? If so, make sure the Disassembler Window is open, then use the green arrow for Asm Step-Into to step to and then into your function. Watch what is happening in the Disassembler Window. There should only be a few instructions before you get to the CALL instruction (or B _dotp), then continue into your assembly function.

    You will be able to step through code in the function that matches with what is in your asm source file. The debugger should be able to Source Step in the asm file, but since that does not appear to be working for you, this method may help you find more about your program so you can track down what went wrong.

    In similar cases to yours, I find myself stepping for a while and then the program is lost. At that point, I have to try to remember where I was just before the failure. That usually means reloading the program and starting over until I can find the instruction that throws it off.

    It is hard to predict what you will find since I do not see anything to predict from. But hopefully your experience with the debugging added to George's expertise looking at your code will help you reach a resolution.

    Regards,
    RandyP
  • Hi RandyP/ George,
    Appreciate your quick and timely response. Now I am able to step through the C as well as assembly code without any issues. Not sure why it did not work before, I followed the same procedure as I followed before. The only difference is I made a clean build now.
    Once again thank you for your prompt support.
    Thanks and Regards,
    Divakar