Shop OBEX P1 Docs P2 Docs Learn Events
Problems CALL'ing empty asm routine — Parallax Forums

Problems CALL'ing empty asm routine

Dennis FerronDennis Ferron Posts: 480
edited 2008-10-11 22:58 in Propeller 1
I wrote an asm subroutine like this:


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

  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-11 21:50
    Yes

    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.
  • Dennis FerronDennis Ferron Posts: 480
    edited 2008-10-11 21:58
    Thanks Mike.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-10-11 22:58
    This is a useful way to implement coroutines, BTW. Initialize the return with the beginning address of the alternate coroutine. Then when each coroutine hands off control to its alternate, it calls the empty subroutine, which stores its resume address after branching to the alternate's resume address.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
Sign In or Register to comment.