Problems CALL'ing empty asm routine
Dennis Ferron
Posts: 480
I wrote an asm subroutine like this:
Since the calling code is time-critical, I wanted to make sure that the mere calling of the subroutine, even if empty, did not cause a problem. When I CALL #TestFunc in my code, it causes strange behavior. This behavior is not seen when I replace the call with nop's; it seems to be caused not by timing but specifically by calling an empty subroutine. I also don't see a problem if I put at least 1 nop in the body of TestFunc; it only happens if the subroutine is empty. Is this related to the trap of needing at least one instruction between a movs and the modified instruction? I'm thinking that call jumps directly to TestFunc, which is actually TestFunc_ret, and the processor doesn't pick up on the modification of the ret destination because no instructions intervened. Is that correct?
TestFunc ' Empty because I haven't put in any code yet TestFunc_ret ret
Since the calling code is time-critical, I wanted to make sure that the mere calling of the subroutine, even if empty, did not cause a problem. When I CALL #TestFunc in my code, it causes strange behavior. This behavior is not seen when I replace the call with nop's; it seems to be caused not by timing but specifically by calling an empty subroutine. I also don't see a problem if I put at least 1 nop in the body of TestFunc; it only happens if the subroutine is empty. Is this related to the trap of needing at least one instruction between a movs and the modified instruction? I'm thinking that call jumps directly to TestFunc, which is actually TestFunc_ret, and the processor doesn't pick up on the modification of the ret destination because no instructions intervened. Is that correct?
Comments
The CALL translates into a "JMPRET TestFunc_ret,#TestFunc" and, if the routine is empty, this becomes "JMPRET TestFunc,#TestFunc". The storage of the return address occurs after the fetch of the next instruction which is where the return address is stored.
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!