Tony Papadimitriou

9S08QE128 Note: INC PPAGE does not set the Z flag when wrapping around from 7 to 0

Discussion created by Tony Papadimitriou on Aug 26, 2008
Latest reply on Aug 27, 2008 by Tony Papadimitriou
I spent about an hour chasing this little gotcha inside a quite large application, so I thought it might be of interest to some of you.

When PPAGE is 7 (last possible ppage) for 9S08QE128, doing INC PPAGE will make PPAGE zero but the Z flag will not be set.

This seemingly wrong result is actually correct in that the MCU internally is incrementing the 7 and getting a non-zero value.  But, when the value is written back to PPAGE only bits 2..0 are affected (doing an implicit AND #7 operation) and the debugger will show you that PPAGE is zero right after the INC instruction executes, but the Z flag will be clear.  So, this:

LDA PPAGE
INCA
AND #7
BEQ DONE
STA PPAGE

works, but the the nicer

INC PPAGE
BEQ DONE

doesn't.



Message Edited by tonyp on 2008-08-27 12:12 AM

Outcomes