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.

TIDM-BUCKBOOST-BIDIR: Context save for assembly function called from ISR

Part Number: TIDM-BUCKBOOST-BIDIR

Hi.

I was modifying the code provided with the TIDM-BUCKBOOST-BIDIR reference design and I came across something I do not understand. My doubt is related to context save for assembly functions called from an ISR. Let us see the following code snippet:

...
_DPL_Func:
		; full context save - push any unprotected registers onto stack
		PUSH  	XAR1
		PUSH  	XAR2
		PUSH  	XAR3
...

This is a portion of code found in file BuckBoostBiDir-DPL.asm. Basically, my doubt is why is it needed to do those pushes?

I have seen "TMS320C28x CPU and Instruction Set - Reference Guide" and the answer to this question and I understood that when an interrupt is served by a function written in assembly code, automatic context save is done only for some specific registers and that then, it depends on the programmer to save other used registers. On the other side, when interrupts are served by functions written in C, the compiler does all the context save automagically. So, this is a kind of border case because the interrupt is served by a C function but then it calls an assembly function... I would have imagined that no context save was needed for the assembly code but those pushes seem to be exactly that. And it would make sense except for the fact that then, when the control macro CNTL_3P3Z is executed, there are others registers used (specifically, XAR4) that were not pushed. So assuming that those pushes are done as context save, would not it be needed to do the same for the other registers used in the aforementioned macro? I definitely lack knowledge of assembly and I do not completely understand how things go on in a normal call to a function written in assembly (Is this explained somewhere? I mean context save for normal calls to functions written in assembly.) but there is something strange with this example. It does not seem consistent to me. Could this last thing I am mentioning be a "bug"?

Thanks in advance!

  • Hi Roman,

    Please refer to chapter 7.5 of TMS320C28x Optimizing C/C++ Compiler user’s guide on how to write assembly function that is designed to be called by C function. The XAR1, XAR2 and XAR3 are responsibility of the function to save and restore if they are being modified within the function. XAR4-XAR7, on the other hand, are responsibility of caller function (compiler generated from in your case) to save and restore if their value are expected to be retained after the function call. You can refer to Table 7-2 of chapter 7.2.1 for more details.

    Han

  • I cannot believe I missed that because I also considered that user's guide. Thank you! Really clear.