Shop OBEX P1 Docs P2 Docs Learn Events
Conditional execution (PASM) woes : RESOLVED (Thanks Phil) — Parallax Forums

Conditional execution (PASM) woes : RESOLVED (Thanks Phil)

TreeLabTreeLab Posts: 138
edited 2009-03-06 13:38 in Propeller 1
Greetings All;
Some PASM code is driving me crazy, and I just do not get it. Any assistance would be most welcome. Here is the pertinent code ...

RunCoil            mov phsb, zero
                   mov Time, cnt
                   add Time, pOnCnt

DriveCoil          mov outa, ActivePin               ' turn pin ON

                   mov outa, zero                    ' turn it off


                   Call #Update

                   cmp phsb, #3        wz, wc
             IF_BE JMP #DriveCoil

DeadCoil           cmp phsb, #5      wz, wc         ' CORRECTED AS PER PHIL's POST; PROBLEM PERSISTS
              IF_B JMP #DeadCoil       
RunCoil_ret        RET                      





I am counting square wave pulses with counter b, and I want to loop within DriveCoil until the phsb exceeds 3. I zero phsb at the start, and in the Update subroutine I send the current value of phsb back to the hub memory, where I examine it with ViewPort.
I can see the phsb increasing exactly as it should at several kHz, but the conditionals never terminate the loop. If I omit the wz,wc effects, I immediately exit the loops.

I am clearly not understanding what is going on here, but it seems pretty obvious. From page 362 of the manual,

CMP Value1, 〈#〉 Value2

CMP (Compare Unsigned) compares the unsigned values of Value1 and Value2. The Z and C
flags, if written, indicate the relative equal, and greater or lesser relationship between the two.
If the WZ effect is specified, the Z flag is set (1) if Value1 equals Value2. If the WC effect is
specified, the C flag is set (1) if Value1 is less than Value2.

The on page 369, the conditionals are described :

IF_BE if below or equal (C | Z = 1) IF_C_OR_Z –and– IF_Z_OR_C

So, can someone explain why my loop never exits?

Cheers!
Paul Rowntree

Post Edited (TreeLab) : 3/6/2009 7:13:41 PM GMT

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-03-06 07:21
    Your comparison in DeadCoil needs to set the conditionals. You're doing that in the next statement.

    -Phil
  • TreeLabTreeLab Posts: 138
    edited 2009-03-06 07:29
    You are quite right Phil, and thanks!, but that was a copy / paste error on my part (2:30 am local time). The problem is that I cannot get out of the loop staring with DriveCoil and ending with the IF_BE

    Cheers!
    Paul Rowntree
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-03-06 08:07
    Try this instead:

            cmp     three,phsb wz,wc
      if_ae jmp     #DriveCoil
            ...
    three   long    3
    
    
    


    The problem is that phsb can't be used as the destination of a read-modify-write (RMF) instruction. Even though you're not modifying it, it's still an RMF (i.e. a SUBtract), but with an automatic nr modifier; and what you're performing the comparison on is phsb's "shadow register". I know it sounds weird, but I'm pretty sure that's what's happening.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 3/6/2009 8:15:50 AM GMT
  • TreeLabTreeLab Posts: 138
    edited 2009-03-06 13:38
    Phil, you are great ... when next in Guelph, Ontario, I will buy you a beer (real beer too !). I do not have a prop here, but I am going to bet that you are right. Thank you ever so much!
    And now that I know what I am looking for, the Datasheet states :

    PHS can only be read through the source operand (same as PAR, CNT, INA, and INB).

    If the Tricks and Traps document is still being maintained, this might be a worthy addition.

    EDIT : This was the problem.

    Cheers, and thanks again!
    Paul Rowntree

    Post Edited (TreeLab) : 3/6/2009 7:12:57 PM GMT

Sign In or Register to comment.