Shift Optimizations

Shifting a byte variable by a constant number of bits is intensively analyzed. The Compiler always tries to implement such shifts in the most efficient way. As an example, consider the following:

  char a, b;

  
  a = b << 4;

  

This disassembles in the following code:

  LDA   b

  
  NSA        ; Swap nibbles...

  
  AND   #-16 ; ...and mask!

  
  STA   a