AnsweredAssumed Answered

TS201 nested assembly function prolog/epilog

Question asked by Steve_E_B on Dec 4, 2014
Latest reply on Aug 27, 2015 by MaheshN

We are using the nested assembly function prolog/epilog for entry/exit for C code compatibility as described in EE241

We found a problem with the nested C calls where one assembly function calls another function with:

 

CALL <function>; q[j27+0X4]=j27:24; q[k27+0X4]=k27:24;;

 

clobbers values on the stack.

 

using code in EE241, prior to the call the stack is:

sp+16: j23:20

sp+12: j19:16

sp+8: r31:28

sp+4: r27:24

sp+0: free

of course, when the function called is, q[j27+0X4]=j27:24 is going to clobber the contents of sp+4

 

our work-around was to offset the saved registers by 4 (i.e. sp+8: r27:24)

that's OK unless you push variables to the stack with q[j27-=4] = reg, then the last var to the stack gets clobbered.

 

It seems a better solution would be to call the subroutine with post-modify:

CALL <function>; q[j27 += -4] = j27:24; q[k27 += -4] = k27:24;;

 

I've noticed that compiler generated function calls use the pre-modify instruction (q[j27+0X4]=j27:24 ...). Not sure why this is preferred. In case of interrupts?

 

Has anyone else encountered this?

Outcomes