Conditional execution (PASM) woes : RESOLVED (Thanks Phil)
TreeLab
Posts: 138
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 ...
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
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
Cheers!
Paul Rowntree
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
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