Shop OBEX P1 Docs P2 Docs Learn Events
CALL w/o RET? — Parallax Forums

CALL w/o RET?

K2K2 Posts: 693
edited 2011-07-05 16:39 in Propeller 1
Since CALL and RET on the Propeller do not involve a stack, would any harm come from putting a second exit point into a CALLed routine, with the second exit point being a JMP? The JMP would be taken only if I never intended to RET at all. (In other words, I would be abandoning that particular execution thread.) Some time later I may CALL the same routine again, and perhaps this time use the RET.

While it may lose a few point in terms of readability or orthodoxy, I haven't thought of any reason why this wouldn't work. But I'm just a grasshopper.

Comments

  • RaymanRayman Posts: 14,876
    edited 2011-07-05 13:47
    I think that would work. Never tried it though...
  • K2K2 Posts: 693
    edited 2011-07-05 14:04
    I'll give it a shot then. If it works, it will be another instance of the Propeller's crazy architecture facilitating uncommon coding efficiencies.
  • jazzedjazzed Posts: 11,803
    edited 2011-07-05 14:17
    Know what you mean mostly, but I'd rather use RET if possible especially when it's free ...
    routine
      ' some code
    
      ' done?
            test done,#1 wc
      if_c  jmp routine_ret ' don't need #
    
      ' more code
            nop
    routine_ret ret
    
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-07-05 14:23
    You can certainly do it. Just ensure your comment makes sense, such as 'abort subroutine without ret
  • tonyp12tonyp12 Posts: 1,951
    edited 2011-07-05 16:01
    It will work just fine, the prop have no idea what subroutines are.
    Even the CALL is just as pseudo op-code that the assembler calculates for you.

    The jmpret simple self-modify it's own jmp_return line.
  • K2K2 Posts: 693
    edited 2011-07-05 16:39
    Thanks for the great answers.

    @ Jazzed: One of the features I like most about the Prop is conditional execution. You've illustrated how convenient it can make branching.

    In the case I'm dealing with, the JMP exit would be taken in response to an error condition detected inside the subroutine. By jumping out of the routine right then, the calling function (which operates at high speed) doesn't have to be cluttered with tests.

    Nevertheless, breaking from established practice usually gets me into trouble. But the trouble could surely be minimized by clear documentation, as Cluso points out.

    @Tony: Thanks for the great explanation. It makes laugh to consider how sly Chip was to employ such simple solutions. That's part of what makes the Prop so much fun to use.
Sign In or Register to comment.