PreviousNext
Equality result
Help > Appendix > Code Optimization > Equality result

FLASH-                        RAM                Speed+

 

When a function result is equality of two expressions, then instead of converting the comparison result to the Carry (used to return bit result) it is better to return the difference and to use the Zero_ MCU flag. Carry flag can be even used for smaller/bigger comparisons too.

 

uns8 var1, var2;

 

bit AreSame ()

{

  return var1 == var2;

}

 

void APPLICATION  ( void )

{

  if ( AreSame() )

       ...

  else if ( var2 > var1 )

       ...

 

}

uns8 var1, var2;

 

uns8 AreSame ()

{

  return var1 - var2;

}

 

void APPLICATION  ( void )

{

  AreSame();

  if ( Zero_ )

       ...

  else if ( !Carry )

       ...

}