Shop OBEX P1 Docs P2 Docs Learn Events
Jumps and flags — Parallax Forums

Jumps and flags

I haven't seen an example of using jumps to set/reset flags before, but I've found them to be useful.
I had a few sections of code with something like this:
mov    t1, #0 wz, nr           ' Set Z, don't alter t1
jmp    #loop                   ' Return to loop
But you can do both in one instruction with:
tjz   inb, #loop wz
In effect, we test inb (which is always zero) and perform the branch, setting the Z flag in the process.
Since the jump takes place, it takes only 4 clock cycles.
Conversely, you can reset Z with:
tjnz  nonzeroValue, #loop wz
nonzeroValue obviously has to always be non-zero. Again, since the branch takes place, it takes only 4 clock cycles.
Both instructions can reset C (regardless of the value) if wc is specified.
The propeller manual seems to imply that you can use jmp to set C. In my testing, however, I was unable to do so, at least with the propeller tool. Possibly it ignores wc on this instruction?
In summary, you can:
Set Z and optionally reset C; or
Reset Z and optionally reset C
at the same time you unconditionally jump.
Walter
Sign In or Register to comment.