Shop OBEX P1 Docs P2 Docs Learn Events
stupid questions about PASM2 — Parallax Forums

stupid questions about PASM2

OK the first one

Am I correct that call...ret does NOT return the state of Z or C but preserves the one outside the call unless I do RET WC WZ?

Comments

  • evanhevanh Posts: 15,915
    I wish! It's the other way around.
  • shhhh., I thought I read it somewhere,

    so after a RET I get the flags from the sub, right? What you mean by 'other way around'?

    Enjoy!

    Mike
  • evanhevanh Posts: 15,915
    I can't use _RET_ and have it preserve the calling flags so that conditional execution works across calls. I have to use RET WCZ instead.
  • so _ret_ or RET will return the changed flags but RET WCZ will preserve them and restore the flags to the point of the call?

    curious,

    Mike
  • Cluso99Cluso99 Posts: 18,069
    There are two cases you need to consider.

    1. A subroutine wants to return any flags it changes to the calling routine.
    eg: on return I set/clear Z &/or C flags to pass results of the subroutine, so Z might be passed/success where NZ is fail/error

    2. A subroutine needs to use flags but the calling program does not want them changed.

    Both of these methods have their advantages and disadvantages.

    The P1 always uses 1. above. If 2. is required, then the subroutine needs to save the flags on entry, and restore them before returning.

    On the P2...
    1. works with
    _RET_ <opcode> <operands>
    and
    RET

    2. works only with
    RET {wc/wz/wcz} where the Z &/or C is preserved only if the modifier is used.
  • thank you @Cluso99 that is a useful explanation.

    Enjoy!

    Mike
Sign In or Register to comment.