PreviousNext
Pointer arithmetic
Help > Appendix > Code Optimization > Pointer arithmetic

FLASH-                        RAM                Speed+

 

When a variable in RAM is traditionally addressed, the variable content could not lie in more than one PIC RAM bank. Therefore, when a pointer value to a variable is calculated the higher byte of the pointer is never changed and the calculation can be done only on the lower byte.

 

  uns8 indexAtBufferINFO;

...
  setFSR0( _FSR_INFO );

  FSR0 += indexAtBufferINFO;

  uns8 indexAtBufferINFO;

...
  setFSR0( _FSR_INFO );

  FSR0L += indexAtBufferINFO;

 

Note: The above code might not work when Linear data memory (0x2‑‑‑) or Program memory (0x8‑‑‑‑ … 0xFFFF) is indirectly addressed. It always works with the Traditional data addressing (0x0‑‑‑) only.

 

Please note that when a constant value (from -32 to +31) is added to an FRSx register, then the calculation should be always done with the whole register as the optimal PIC ADDFSR instruction is generated.

 

  setFSR0( _FSR_INFO );

  FSR0 += 12;