Shop OBEX P1 Docs P2 Docs Learn Events
PASM: WAITPNE results and flags — Parallax Forums

PASM: WAITPNE results and flags

johnfosjohnfos Posts: 59
edited 2011-05-05 06:57 in Propeller 1
Pursuing my attempts to understand the propeller assembly language, I think I have one last question.

If WAITPNE is used with the wz, wc and wr effects, under what conditions are the flags set and what algorithm determines the result?

I've found a number of posts relating to this, but I haven't been able to piece together the whole picture. Kuroneko has said that the result is D += S + 1, which I don't dispute but which is at odds with the first and last lines of the truth table on page 370 of the propeller manual (v1.1). If the truth table is wrong, it's the only such case I've been able to find.

I've also seen it said that Z is set if the final D value is 0, which makes sense and is in line with the truth table.

And I have no idea how the C flag is set.

By the way, many thanks to Dave Hein for his SpinSim program. Without that, I'd have had a lot more questions. Unfortunately, SpinSim doesn't implement WAITPNE and its chums.

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-05-04 17:02
    johnfos wrote: »
    If WAITPNE is used with the wz, wc and wr effects, under what conditions are the flags set and what algorithm determines the result?
    All waitxxx instructions use add as their primary function (with the - for want of a better word - exception of waitpneA). Therefore the flag behaviour is the same as for add. The wait part is done with extra h/w (the ALU is not used for this).

    Why waitpne is special (+1) is everyone's guess but it sure is convenient when you know about it.
    johnfos wrote: »
    ... but which is at odds with the first and last lines of the truth table on page 370 of the propeller manual (v1.1). If the truth table is wrong, it's the only such case I've been able to find.
    Lucky! Imagine you'd found more. While I can't disprove the first line (infinite block) the last line is evidently wrong. Running a test here tells me 5 and both flags clear. If you want to see a zero result check
    waitpne m2, #1 wc,wz,wr
    
    m2      long    -2
    
    which gives 0 and both flags set.


    Regarding the only such case, the carry flag behaviour description/footnote for jmp[ret] is wrong (and so is the truth table). Also, for practical purposes the zero flag is always cleared, the only case where it could be 1 (PC = $1FF) aborts the instruction (nop) so flags are not changed at all.

    A It's still add but not as expected.
  • kuronekokuroneko Posts: 3,623
    edited 2011-05-05 01:00
    wrlong, zero flag behaviour
    The Z flag is always cleared (0) since the main memory address (bits 13:2) is always on a long boundary.

    Brilliant! Did I just open a can of worms?


    For the terminally curious the Z flag is actually set for
    [B]wrbyte[/B]: D[ 7..0] == 0
    [B]wrword[/B]: D[15..0] == 0
    [B]wrlong[/B]: D[31..0] == 0
    
    226 x 170 - 13K
  • johnfosjohnfos Posts: 59
    edited 2011-05-05 06:46
    Thanks Kuroneko - brilliant answer. So in WAITPNE 0,#0 we also have a HALT instruction.

    This raises a new question: is there anywhere a list of known errata in the manual? I can find the list of changes between versions, but if there's an errata list it's eluded me.

    This all arose, by the way, in testing my simulator. I wrote a program to parse the instruction descriptions and truth tables out of the manual and auto-generate test programs for most instructions (not jump instructions), so if there are other errors in the manual I may not have spotted them. My simulator is an educational exercise; it's never going to be a rival for SpinSim.
  • kuronekokuroneko Posts: 3,623
    edited 2011-05-05 06:57
    johnfos wrote: »
    So in WAITPNE 0,#0 we also have a HALT instruction.
    Provided register 0 is in fact #0. Better is waitpeq $, #0 (most of the time waitpne par, #0 will do). Or if you want a proper HALT set the clock register to $02.
    johnfos wrote: »
    This raises a new question: is there anywhere a list of known errata in the manual? I can find the list of changes between versions, but if there's an errata list it's eluded me.
    Nothing I'm aware off. Currently I have a support request filed to get the documentation updated (not sure how this will be handled re: QC). Apart from that you'll have to dig through the forum posts or just ask.
Sign In or Register to comment.