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.

Calling C function from assembly code

Hello,

I am trying to call C function from Assembly File. But couldnt find any document where function is actually called.  Please provide syntax for the same.

Regards,

	.cdecls C,LIST, "sense.h"
	.global Isense                  ;; Isense is afunction defined in sense.h


ISR: 

;;;some assembly code

calling C function Isense

;;;some assembly code

.end

  • By looking at your other posts, I can see that you use a C28x processor.  

    It appears you want to implement an interrupt service routine (ISR) in hand-coded assembly, and have it call a C function.  Is that correct?  Can this ISR presume the C environment (particularly the stack) has been established?  

    Hoping to find an example, I checked our manuals, wiki articles, and the like.  I have not found anything yet.

    Thanks and regards,

    -George

  • Hello George,

    I am really sorry for not mentioning Controller Family on which I am working.
    Yes on both of your questions. Manual talks about this but doesnt provide syntax or examples.

    Regards,
  • I cannot find an example.  I think I can come up with most of one.  But I will not get to that today.

    Thanks and regards,

    -George

  • Hello George,

    I used following command to call C function.
    LCR #_Isense
    I could see that my C function is called but when my CPU comes out of ISR,CPU is tapped in ISR_Illegal. In Disassembly I saw this occur when CPU executes SPM #0. What I am missing here?

    Regards,
  • Shiv Aishwarya Singh said:
    What I am missing here?

    I'm not sure.  My guess is you are not returning from the interrupt with the instruction IRET.  This quote is from the C28x CPU book ...

    The IRET instruction restores the PC value and other register values that were automatically saved by an interrupt operation.

    Recall I told you I would show an example to work with.  I gave it a go.  I now think I lack the expertise needed to do this reliably.  I started by compiling this C routine ...

    interrupt void isr()
    {
       Isense();
    }

    That's how you would do it in C.  I built with the option --src_interlist.  This option causes the compiler to not delete the resulting .asm file, and add some comments which make it easier to follow.  I understand the resulting assembly at a high level.  But I cannot explain it in close detail.  I will ask other experts to comment on this thread.

    Thanks and regards,

    -George

  • Hello,

    In addition to what George mentioned regarding using IRET (which is required for an ISR) and looking at the assembly, refer to the following two posts which are very similar and may assist in resolving issues you are seeing.

    e2e.ti.com/.../1336139
    e2e.ti.com/.../1481744

    Best Regards
    Chris
  • Hii Chris,

    Saving RPC solved the issue.

    Thanks

    Regards,

    Shiv