Shop OBEX P1 Docs P2 Docs Learn Events
nested reps — Parallax Forums

nested reps

I am guessing that nested reps are a no-no?

{Spin2_v52}
CON ' Constants

    _CLKFREQ = 160_000_000


PUB start() | i, c
org
    rep @.outerloop, #10
     rep @.innerloop, #10
      add c, #1
 .innerloop
     add i, #1    
.outerloop

end
debug(udec(c))
debug(udec(i))

Comments

  • JonnyMacJonnyMac Posts: 9,572
    edited 2026-01-07 02:03

    I got something similar

    Easy to fix, though

  • No, you can't nest reps. Ada tells us all about it here

  • TonyB_TonyB_ Posts: 2,255
    edited 2026-01-07 12:41

    @bob_g4bby said:
    No, you can't nest reps. Ada tells us all about it here

    That doc also says: "The last instruction in the REP loop should not be a relative-addressed jump or call, since the PC will already have looped back to the top by the time the target address is computed."

    A relative-addressed jump or call can definitely be the last instruction as long as the number of REP instructions is added to the branch address, e.g. tjz x,#branch_address+4 if four repeated instructions. (Just tested this successfully in cog exec.)

  • Of course you can do it if you correct for the looping, but the point is that it doesn't work normally.

Sign In or Register to comment.