Shop OBEX P1 Docs P2 Docs Learn Events
wc,wz,etc - a question — Parallax Forums

wc,wz,etc - a question

pik33pik33 Posts: 2,398
edited 2012-05-15 10:26 in Propeller 1
I don't fully understand working of wc and wz modifiers.

For example:

when
sub a,b
is a zero flag set always when result is 0, or I have to write
sub a,b wz
?

If first answer is correct - how o write
sub a,b
in way that flags will not be overwritten?

I want something like this:
               cmp a,b wz
if_z         sub c,d
if_z         sub e,f
if_z         sub g,h


so if a=b then do these three subs; but I don't know if these subs writes flags or not, so I did it in this way
          cmp a,b wz
if_nz  jmp next
         sub c,d
         sub e,f
         sub g,h
next  rest_of_code


maybe wasting a long and 4 cycles for jump.

Comments

  • ctwardellctwardell Posts: 1,716
    edited 2012-05-15 05:49
    My understanding is that the flags are only written when the cooresponding wc or wz modifier is used, so your code without the jump should work fine.

    C.W.
  • Mark_TMark_T Posts: 1,981
    edited 2012-05-15 07:24
    In general WZ and WC are necessary to set the flags, and NR is needed to suppress writing the destination (except for a few exceptional instructions like TEST).

    Having the flags unaffected by default makes it easy to see which instruction last affected the flag you're testing which I think makes PASM easier to comprehend.

    [ BTW the assembler reference always shows you the defaults for the WZ,WC and R flag modifiers for every instruction - read the whole section 2 or 3 times and you'll save a lot of time in the future I think ]
  • Heater.Heater. Posts: 21,230
    edited 2012-05-15 07:45
    Yep, flags will not be set unless you ask for it with wz, wc modifiers. So your code will do what you want.
    This is a very valuable feature of the Prop instruction set architecture, can save a lot of testing and jumping which is important if you have such a limited space to work in as the COG does.
    Can't remember the details but you will find that some instruction mnemonics are actually the same opcode but with different settings for nr. So sub and cmp are the same except cmp has nr set.
  • pik33pik33 Posts: 2,398
    edited 2012-05-15 10:26
    12 cycles saved :)

    This assembler reference fooled me with these defaults; I thought when using "sub" wz is set by default and did't know how to switch it off.
Sign In or Register to comment.