PreviousNext
Carry as a variable
Help > Appendix > Code Optimization > Carry as a variable

FLASH-                        RAM-               Speed+

 

Sometimes the Carry MCU flag can be carefully and efficiently used as a variable.

 

Also, the following example shows how to compare and store the last value in one step.

 

// Keeps Carry, changes Zero_

#define XorWithAndCopyTo(value,xorWithAndCopyTo) do { \

  W = value; \

  xorWithAndCopyTo ^= W; \

  xorWithAndCopyTo = W; } while(0)

 

// Compare and copy the last values of PID, TX, and PCMD to detect duplicate packets

Carry = FALSE;

 

XorWithAndCopyTo( PID, lastPID );

if ( !Zero_ )

  Carry = TRUE;

 

XorWithAndCopyTo( TX, lastTX );

if ( !Zero_ )

  Carry = TRUE;

 

XorWithAndCopyTo( _PCMD, lastPCMD );

if ( !Zero_ )

  Carry = TRUE;

 

// At least one of 3 parameters must be different to use the packet

if ( !Carry )

...