CALL and C/Z flags
ManAtWork
Posts: 2,176
in Propeller 2
To code an IF..THEN..ELSE in pasm as short as possible I had the idea of something like this:
testb flags,#2 wc if_c call #ThenFunc if_nc call #ElseFuncFor this to work correctly I have to make sure that the C flag is preserved until after the first call. The P2 instructions docs say that CALL pushes the C/Z flags onto the stack. But how are they restored? Do I have to add a wcz postfix to the RET instruction? If yes then I can't use the _ret_ prefix, right? A wcz after the CALL is wrong, I think. It would set C=D[31] and Z=D[30] according to the docs.
Comments
_RET_ does not have any spare bits left to enable/disable restoring the flags.
In the ROM SD driver and the serial/debugger I have the need for both cases. In the SD Driver I pass back the flags from the bottom level routine right back up to the top. I have carefully crafted the code to do this. In the serial/monitor, since it is a bunch of callable routines form user code, I preserve the flags.
You win some and lose some on the roundabout. I use both, probably equally in number.
In fact what would have been nicer is if the standard RET [wc/wz/wcz] could also have had an option [sc/sz/scz/cc/cz/ccz] so that the c and/or z flags could also be cleared/set. Though preceding with MODCZ is easy enough.
I basically never use _RET_ now.
And BTW, can somebody please point me to the document where the arguments to MODCZ are explained? I know there are some predefined constants so I don't have to use binary literals. But I forgot them...
sets C (ie C) and clears Z (ie NZ)